Class: CableReady::Updatable::CollectionsRegistry
- Inherits:
-
Object
- Object
- CableReady::Updatable::CollectionsRegistry
- Defined in:
- app/models/concerns/cable_ready/updatable/collections_registry.rb
Instance Method Summary collapse
- #broadcast_for!(model, operation) ⇒ Object
-
#initialize ⇒ CollectionsRegistry
constructor
A new instance of CollectionsRegistry.
- #register(collection) ⇒ Object
Constructor Details
#initialize ⇒ CollectionsRegistry
Returns a new instance of CollectionsRegistry.
18 19 20 |
# File 'app/models/concerns/cable_ready/updatable/collections_registry.rb', line 18 def initialize @registered_collections = [] end |
Instance Method Details
#broadcast_for!(model, operation) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/models/concerns/cable_ready/updatable/collections_registry.rb', line 26 def broadcast_for!(model, operation) @registered_collections.select { |c| c.[:on].include?(operation) } .each do |collection| resource = find_resource_for_update(collection, model) next if resource.nil? collection.klass.cable_ready_update_collection(resource, collection.name, model, debounce: collection.debounce_time) if collection.[:if].call(resource) end end |
#register(collection) ⇒ Object
22 23 24 |
# File 'app/models/concerns/cable_ready/updatable/collections_registry.rb', line 22 def register(collection) @registered_collections << collection end |