Class: CableReady::Updatable::CollectionsRegistry

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/cable_ready/updatable/collections_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeCollectionsRegistry

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.options[: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.options[: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