lib/ar_sync/collection.rb in ar_sync-1.0.1 vs lib/ar_sync/collection.rb in ar_sync-1.0.2
- old
+ new
@@ -9,15 +9,10 @@
@order = order
self.class.defined_collections[[klass, name]] = self
define_singleton_method(name) { to_a }
end
- 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
-
def to_a
all = klass.all
all = all.order id: order if order
all = all.limit limit if limit
all
@@ -28,38 +23,18 @@
end
def self.find(klass, name)
defined_collections[[klass, name]]
end
-end
-class ArSync::Collection::Tree < ArSync::Collection
- def initialize(*)
- super
- @field = ArSync::CollectionField.new @name, limit: @limit, order: @order
- self.class._sync_children_info[[@klass, @name]] = @field
- end
+ def _sync_notify_child_changed(_name, _to_user); end
- def _sync_notify_parent(*); end
-
- def self._sync_children_info
- @sync_children_info ||= {}
+ 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
- def self._sync_child_info(key)
- _sync_children_info[key]
- end
-end
-
-class ArSync::Collection::Graph < ArSync::Collection
- def _sync_notify_child_changed(_child, _name, _to_user, _owned); end
-
- def _sync_notify_child_added(child, _name, to_user, _owned)
- ArSync.sync_graph_send to: self, action: :add, model: child, path: :collection, to_user: to_user
- end
-
def _sync_notify_child_removed(child, _name, to_user, _owned)
- ArSync.sync_graph_send to: self, action: :remove, model: child, path: :collection, to_user: to_user
+ ArSync.sync_send to: self, action: :remove, model: child, path: :collection, to_user: to_user
end
def self._sync_children_info
@sync_children_info ||= {}
end