Module: ActivityObject::Properties::ClassMethods

Defined in:
app/models/activity_object/properties.rb

Instance Method Summary collapse

Instance Method Details

#property_reflections(objects, options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/activity_object/properties.rb', line 78

def property_reflections objects, options = {}
  objects.each do |o|
    source = options[:source] || o
    conditions = options[:conditions] && { type: o.to_s.classify } || nil

    attr_reader "add_holder_#{ o }_id" # attr_reader "add_holder_post_id"

    has_many o.to_s.tableize,             # has_many posts,
             through: :property_objects,  #          through: :property_objects,
             source:  source,             #          source:  :post
             conditions: conditions

    has_one  "main_#{ o }",                  # has_one :main_post,
             through: :main_property_object, #         through: :main_property_object,
             source: source,                 #         source:  :post
             conditions: conditions

    has_many "holder_#{ o.to_s.tableize }",  # has_many :holder_posts,
             through: :holder_objects,       #          through: :holder_objects,
             source: source,                 #          source:  :post
             conditions: conditions

    has_many "main_holder_#{ o.to_s.tableize }", # has_many :main_holder_posts,
             through: :main_holder_objects,      #          through: :main_holder_objects,
             source:  source,                    #          source:  :post
             conditions: conditions

  end
end