Class: CouchRest::Model::CollectionOfProxy
- Inherits:
-
CastedArray
- Object
- Array
- CastedArray
- CouchRest::Model::CollectionOfProxy
show all
- Defined in:
- lib/couchrest/model/associations.rb
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
#build, #clear, #delete, #delete_at
Methods included from Dirty
#couchrest_attribute_will_change!, #couchrest_parent_will_change!, #use_dirty?
Methods included from CastedBy
#base_doc, #base_doc?
Constructor Details
- (CollectionOfProxy) initialize(array, property, parent)
A new instance of CollectionOfProxy
177
178
179
180
181
182
183
184
185
|
# File 'lib/couchrest/model/associations.rb', line 177
def initialize(array, property, parent)
(array ||= []).compact!
super(array, property, parent)
casted_by[casted_by_property.to_s] = [] array.compact.each do |obj|
check_obj(obj)
casted_by[casted_by_property.to_s] << obj.id
end
end
|
Instance Method Details
- (Object) <<(obj)
187
188
189
190
191
|
# File 'lib/couchrest/model/associations.rb', line 187
def << obj
check_obj(obj)
casted_by[casted_by_property.to_s] << obj.id
super(obj)
end
|
- (Object) []=(index, obj)
205
206
207
208
209
|
# File 'lib/couchrest/model/associations.rb', line 205
def []= index, obj
check_obj(obj)
casted_by[casted_by_property.to_s][index] = obj.id
super(index, obj)
end
|
- (Object) pop
211
212
213
214
|
# File 'lib/couchrest/model/associations.rb', line 211
def pop
casted_by[casted_by_property.to_s].pop
super
end
|
- (Object) push(obj)
193
194
195
196
197
|
# File 'lib/couchrest/model/associations.rb', line 193
def push(obj)
check_obj(obj)
casted_by[casted_by_property.to_s].push obj.id
super(obj)
end
|
- (Object) shift
216
217
218
219
|
# File 'lib/couchrest/model/associations.rb', line 216
def shift
casted_by[casted_by_property.to_s].shift
super
end
|
- (Object) unshift(obj)
199
200
201
202
203
|
# File 'lib/couchrest/model/associations.rb', line 199
def unshift(obj)
check_obj(obj)
casted_by[casted_by_property.to_s].unshift obj.id
super(obj)
end
|