Sha256: f68600edc0751d130289fa131774d92e5f0ccfa049582381dffaab47f2128997

Contents?: true

Size: 967 Bytes

Versions: 27

Compression:

Stored size: 967 Bytes

Contents

module C80MapFloors

  class MapJson < ActiveRecord::Base

    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

    def self.fetch_json
      locations_path = Rails.root.join("public", "locations.json")
      locs = File.read(locations_path)
      JSON.parse(locs)
    end

  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
c80_map_floors-0.2.2 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.1 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.8 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.7 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.6 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.5 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.4 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.3 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.2 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.1 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.2.0.0 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.25 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.24 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.23 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.22 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.21 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.20 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.19 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.18 app/models/c80_map_floors/map_json.rb
c80_map_floors-0.1.0.17 app/models/c80_map_floors/map_json.rb