Class: SimplyStored::Couch::HasMany::Property

Inherits:
AssociationProperty show all
Defined in:
lib/simply_stored/couch/has_many.rb

Instance Attribute Summary

Attributes inherited from AssociationProperty

#name, #options

Instance Method Summary collapse

Methods inherited from AssociationProperty

#association?, #build, #dirty?, #serialize, #supports_dirty?

Constructor Details

#initialize(owner_clazz, name, options = {}) ⇒ Property

Returns a new instance of Property.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/simply_stored/couch/has_many.rb', line 134

def initialize(owner_clazz, name, options = {})
  options = {
    :dependent => :nullify,
    :through => nil,
    :class_name => name.to_s.singularize.camelize,
    :foreign_key => nil
  }.update(options)
  @name, @options = name, options
  
  options.assert_valid_keys(:dependent, :through, :class_name, :foreign_key)
  
  if options[:through]
    owner_clazz.class_eval do
      _define_cache_accessors(name, options)
      define_has_many_through_getter(name, options, options[:through])
      define_has_many_count(name, options, options[:through])
    end
  else
    owner_clazz.class_eval do
      _define_cache_accessors(name, options)
      define_has_many_getter(name, options)
      define_has_many_setter_add(name, options)
      define_has_many_setter_remove(name, options)
      define_has_many_setter_remove_all(name, options)
      define_has_many_count(name, options)
    end
  end
end