Class: ArSync::Collection
- Inherits:
-
Object
- Object
- ArSync::Collection
- Defined in:
- lib/ar_sync/collection.rb
Defined Under Namespace
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
Instance Method Summary collapse
-
#initialize(klass, name, limit: nil, order: nil) ⇒ Collection
constructor
A new instance of Collection.
- #sync_send_event(type:, to_user: nil, data:) ⇒ Object
- #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
.defined_collections ⇒ Object
26 27 28 |
# File 'lib/ar_sync/collection.rb', line 26 def self.defined_collections @defined_collections ||= {} end |
.find(klass, name) ⇒ Object
30 31 32 |
# File 'lib/ar_sync/collection.rb', line 30 def self.find(klass, name) defined_collections[[klass, name]] end |
Instance Method Details
#sync_send_event(type:, to_user: nil, data:) ⇒ Object
14 15 16 17 |
# File 'lib/ar_sync/collection.rb', line 14 def sync_send_event(type:, to_user: nil, data:) event_data = { type: type, data: data } ArSync.sync_tree_send to: self, action: :event, path: [], data: event_data, to_user: to_user end |
#to_a ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ar_sync/collection.rb', line 19 def to_a all = klass.all all = all.order id: order if order all = all.limit limit if limit all end |