Class: C80MapFloors::MapJson
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- C80MapFloors::MapJson
- Defined in:
- app/models/c80_map_floors/map_json.rb
Class Method Summary collapse
Class Method Details
.fetch_json ⇒ Object
28 29 30 31 32 |
# File 'app/models/c80_map_floors/map_json.rb', line 28 def self.fetch_json locations_path = Rails.root.join("public", "locations.json") locs = File.read(locations_path) JSON.parse(locs) end |
.update_json ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/c80_map_floors/map_json.rb', line 5 def self.update_json # открываем файл на чтение locations_path = Rails.root.join("public", "locations.json") locs = File.read(locations_path) locs_hash = JSON.parse(locs) # поместим в него детей - здания со всеми детьми и внуками buildings = [] C80MapFloors::MapBuilding.all.each do |map_building| buildings << map_building.my_as_json5 end locs_hash["buildings"] = buildings # запишем в файл Rails.logger.debug '[TRACE] <map_json.update_json> Запишем JSON в файл.' File.open(locations_path, 'w') do |f| f.write(locs_hash.to_json) end end |