Class: Meek::CollectionProxy
- Inherits:
-
Object
- Object
- Meek::CollectionProxy
- Defined in:
- lib/meek/collection_proxy.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#proxy_association ⇒ Object
Returns the value of attribute proxy_association.
Instance Method Summary collapse
- #<<(*records) ⇒ Object (also: #push, #append)
-
#clear ⇒ Object
Equivalent to
delete_all
. -
#concat(new) ⇒ Object
replace, delete_all, destroy_all, delete, destroy, distinct, uniq,.
-
#initialize(model, association) ⇒ CollectionProxy
constructor
A new instance of CollectionProxy.
- #prepend(*args) ⇒ Object
-
#reload ⇒ Object
Reloads the collection from the database.
-
#reset ⇒ Object
Unloads the association.
Constructor Details
#initialize(model, association) ⇒ CollectionProxy
Returns a new instance of CollectionProxy.
6 7 8 |
# File 'lib/meek/collection_proxy.rb', line 6 def initialize model, association @proxy_association = Meek::ProxyAssociation.new(model, association) end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/meek/collection_proxy.rb', line 4 def model @model end |
#owner ⇒ Object
Returns the value of attribute owner.
4 5 6 |
# File 'lib/meek/collection_proxy.rb', line 4 def owner @owner end |
#proxy_association ⇒ Object
Returns the value of attribute proxy_association.
4 5 6 |
# File 'lib/meek/collection_proxy.rb', line 4 def proxy_association @proxy_association end |
Instance Method Details
#<<(*records) ⇒ Object Also known as: push, append
22 23 24 25 |
# File 'lib/meek/collection_proxy.rb', line 22 def <<(*records) records.map {|record| record.save } proxy_association.concat(records) && self end |
#clear ⇒ Object
Equivalent to delete_all
. The difference is that returns self
, instead of an array with the deleted objects, so methods can be chained. See delete_all
for more information. Note that because delete_all
removes records by directly running an SQL query into the database, the updated_at
column of the object is not changed.
39 40 41 42 |
# File 'lib/meek/collection_proxy.rb', line 39 def clear delete_all self end |
#concat(new) ⇒ Object
replace, delete_all, destroy_all, delete, destroy, distinct, uniq,
18 19 20 |
# File 'lib/meek/collection_proxy.rb', line 18 def concat new proxy_association.concat(new) end |
#prepend(*args) ⇒ Object
29 30 31 |
# File 'lib/meek/collection_proxy.rb', line 29 def prepend(*args) raise NoMethodError, "prepend on association is not defined. Please use << or append" end |
#reload ⇒ Object
Reloads the collection from the database. Returns self
.
45 46 47 48 |
# File 'lib/meek/collection_proxy.rb', line 45 def reload proxy_association.reload self end |
#reset ⇒ Object
Unloads the association. Returns self
.
51 52 53 54 55 |
# File 'lib/meek/collection_proxy.rb', line 51 def reset proxy_association.reset proxy_association.reset_scope self end |