Sha256: 9473d00a7f2b7240c6a579eb628f15505fab27726dda3c901d63353121114d8f

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module C80MapFloors

  module FloorRepresentator

    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_floor_representator
        class_eval do

          has_one :floor, :as => :map_floor_representator, :class_name => 'C80MapFloors::Floor', :dependent => :nullify
          # after_save :update_json # NOTE:: возможно, временно

          def self.unlinked_floors
            res = []
            self.all.each do |sfloor|
              unless sfloor.floor.present?
                res << sfloor
              end
            end
            res
          end

          def update_json
            MapJson.update_json
          end

        end
      end
    end

    module InstanceMethods

      # noinspection RubyResolve
      def my_as_json3
        result = {
            id:               self.id,
            ord:              self.ord,
            title:            self.title,
            square:           self.square,
            square_free:      self.square_free,
            areas_count:      self.areas.count,
            areas_free_count: self.areas.free_areas.count,
            price_string:     self.price_string
        }
        result.as_json
      end

    end

  end
end

ActiveRecord::Base.send :include, C80MapFloors::FloorRepresentator

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
c80_map_floors-0.1.0.4 app/models/c80_map_floors/floor_representator.rb