Class: ArSync::Collection
- Inherits:
-
Object
- Object
- ArSync::Collection
- Defined in:
- lib/ar_sync/collection.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Class Method Summary collapse
- ._sync_child_info(key) ⇒ Object
- ._sync_children_info ⇒ Object
- .defined_collections ⇒ Object
- .find(klass, name) ⇒ Object
Instance Method Summary collapse
- #_sync_notify_child_added(child, _name, to_user) ⇒ Object
- #_sync_notify_child_changed(_name, _to_user) ⇒ Object
- #_sync_notify_child_removed(child, _name, to_user, _owned) ⇒ Object
-
#initialize(klass, name, limit: nil, order: nil) ⇒ Collection
constructor
A new instance of Collection.
- #to_a ⇒ Object
Constructor Details
#initialize(klass, name, limit: nil, order: nil) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 9 10 11 12 |
# File 'lib/ar_sync/collection.rb', line 5 def initialize(klass, name, limit: nil, order: nil) @klass = klass @name = name @limit = limit @order = order self.class.defined_collections[[klass, name]] = self define_singleton_method(name) { to_a } end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/ar_sync/collection.rb', line 4 def klass @klass end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/ar_sync/collection.rb', line 4 def limit @limit end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ar_sync/collection.rb', line 4 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/ar_sync/collection.rb', line 4 def order @order end |
Class Method Details
._sync_child_info(key) ⇒ Object
43 44 45 |
# File 'lib/ar_sync/collection.rb', line 43 def self._sync_child_info(key) _sync_children_info[key] end |
._sync_children_info ⇒ Object
39 40 41 |
# File 'lib/ar_sync/collection.rb', line 39 def self._sync_children_info @sync_children_info ||= {} end |
.defined_collections ⇒ Object
21 22 23 |
# File 'lib/ar_sync/collection.rb', line 21 def self.defined_collections @defined_collections ||= {} end |
.find(klass, name) ⇒ Object
25 26 27 |
# File 'lib/ar_sync/collection.rb', line 25 def self.find(klass, name) defined_collections[[klass, name]] end |
Instance Method Details
#_sync_notify_child_added(child, _name, to_user) ⇒ Object
31 32 33 |
# File 'lib/ar_sync/collection.rb', line 31 def _sync_notify_child_added(child, _name, to_user) ArSync.sync_send to: self, action: :add, model: child, path: :collection, to_user: to_user end |
#_sync_notify_child_changed(_name, _to_user) ⇒ Object
29 |
# File 'lib/ar_sync/collection.rb', line 29 def _sync_notify_child_changed(_name, _to_user); end |
#_sync_notify_child_removed(child, _name, to_user, _owned) ⇒ Object
35 36 37 |
# File 'lib/ar_sync/collection.rb', line 35 def _sync_notify_child_removed(child, _name, to_user, _owned) ArSync.sync_send to: self, action: :remove, model: child, path: :collection, to_user: to_user end |
#to_a ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ar_sync/collection.rb', line 14 def to_a all = klass.all all = all.order id: order if order all = all.limit limit if limit all end |