Sha256: e6db38e06b93d0561a0c7dbecde6fed5f91d3280424d6ee3d80a771ab17d195d

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

module C80Map

  module AreaRepresentator

    extend ActiveSupport::Concern

    #  ERROR: Cannot define multiple 'included' blocks for a Concern
    # included do
    #
    # end

    def self.included(klass)
      klass.extend ClassMethods
      klass.send(:include, InstanceMethods)
    end

    module ClassMethods

      def acts_as_map_area_representator
        class_eval do

          has_many :map_areas, :as => :area_representator, :class_name => 'C80Map::Area', :dependent => :destroy
          after_save :update_json

          def self.unlinked_areas
            res = []
            self.all.each do |area|
              if area.map_areas.count == 0
                res << area
              end
            end
            res
          end

          def update_json
            MapJson.update_json
          end

        end
      end
    end

    module InstanceMethods

      def to_hash_a
        res = {
            id: id,
            title: title,
            props: {
                square: square,
                floor_height: floor_height,
                gate_type: gate_type,
                desc: desc,
                column_step: column_step,
                communications: communications,
                price: price_string
            }
        }
        res
      end

      # свободна ли площадь, привязанная к полигону на карте
      def is_free?
        res = true
        if map_areas.count > 0
          res = map_areas.first.is_free?
        end
        res
      end
    end

  end
end

ActiveRecord::Base.send :include, C80Map::AreaRepresentator

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
c80_map-0.1.0.24 app/models/c80_map/area_representator.rb
c80_map-0.1.0.23 app/models/c80_map/area_representator.rb
c80_map-0.1.0.22 app/models/c80_map/area_representator.rb
c80_map-0.1.0.21 app/models/c80_map/area_representator.rb
c80_map-0.1.0.20 app/models/c80_map/area_representator.rb
c80_map-0.1.0.19 app/models/c80_map/area_representator.rb
c80_map-0.1.0.18 app/models/c80_map/area_representator.rb
c80_map-0.1.0.17 app/models/c80_map/area_representator.rb
c80_map-0.1.0.16 app/models/c80_map/area_representator.rb
c80_map-0.1.0.15 app/models/c80_map/area_representator.rb