Class: CouchRest::Model::CollectionOfProxy
Overview
Special proxy for a collection of items so that adding and removing to the list automatically updates the associated property.
Instance Attribute Summary
Attributes inherited from CastedArray
#casted_by_property
Instance Method Summary
collapse
Methods inherited from CastedArray
#as_couch_json, #build, #clear, #delete, #delete_at, #insert
Methods included from Dirty
#couchrest_attribute_will_change!, #couchrest_parent_will_change!, #use_dirty?
Methods included from CastedBy
#base_doc, #base_doc?
Constructor Details
#initialize(array, property, parent) ⇒ CollectionOfProxy
Returns a new instance of CollectionOfProxy.
183
184
185
186
187
188
189
190
191
|
# File 'lib/couchrest/model/associations.rb', line 183
def initialize(array, property, parent)
(array ||= []).compact!
super(array, property, parent)
self.casted_by_attribute = [] array.compact.each do |obj|
check_obj(obj)
casted_by_attribute << obj.id
end
end
|
Instance Method Details
#<<(obj) ⇒ Object
193
194
195
196
197
|
# File 'lib/couchrest/model/associations.rb', line 193
def << obj
check_obj(obj)
casted_by_attribute << obj.id
super(obj)
end
|
#[]=(index, obj) ⇒ Object
211
212
213
214
215
|
# File 'lib/couchrest/model/associations.rb', line 211
def []= index, obj
check_obj(obj)
casted_by_attribute[index] = obj.id
super(index, obj)
end
|
#pop ⇒ Object
217
218
219
220
|
# File 'lib/couchrest/model/associations.rb', line 217
def pop
casted_by_attribute.pop
super
end
|
#push(obj) ⇒ Object
199
200
201
202
203
|
# File 'lib/couchrest/model/associations.rb', line 199
def push(obj)
check_obj(obj)
casted_by_attribute.push obj.id
super(obj)
end
|
#shift ⇒ Object
222
223
224
225
|
# File 'lib/couchrest/model/associations.rb', line 222
def shift
casted_by_attribute.shift
super
end
|
#unshift(obj) ⇒ Object
205
206
207
208
209
|
# File 'lib/couchrest/model/associations.rb', line 205
def unshift(obj)
check_obj(obj)
casted_by_attribute.unshift obj.id
super(obj)
end
|