class JSON_storage_strategy
Public Instance Methods
Source
# File lib/models/data_storage_strategy/JSON_storage_strategy.rb, line 7 def read(file_path) return [] unless File.exist?(file_path) data = JSON.parse(File.read(file_path), symbolize_names: true) rescue [] data.map do |data| Student.new(**data) end end
read from json file
Source
# File lib/models/data_storage_strategy/JSON_storage_strategy.rb, line 16 def write(file_path, students) data = students.map { |student| student.to_h } File.write(file_path, JSON.pretty_generate(data)) end
read to json file