Class: CableReady::Channel
- Inherits:
-
Object
- Object
- CableReady::Channel
- Defined in:
- lib/cable_ready/channel.rb
Instance Attribute Summary collapse
-
#available_operations ⇒ Object
readonly
Returns the value of attribute available_operations.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #broadcast(clear) ⇒ Object
- #broadcast_to(model, clear) ⇒ Object
-
#initialize(identifier, available_operations) ⇒ Channel
constructor
A new instance of Channel.
Constructor Details
#initialize(identifier, available_operations) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 11 12 13 14 |
# File 'lib/cable_ready/channel.rb', line 7 def initialize(identifier, available_operations) @identifier = identifier @available_operations = available_operations reset available_operations.each do |available_operation, implementation| define_singleton_method available_operation, &implementation end end |
Instance Attribute Details
#available_operations ⇒ Object (readonly)
Returns the value of attribute available_operations.
5 6 7 |
# File 'lib/cable_ready/channel.rb', line 5 def available_operations @available_operations end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/cable_ready/channel.rb', line 5 def identifier @identifier end |
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
5 6 7 |
# File 'lib/cable_ready/channel.rb', line 5 def operations @operations end |
Instance Method Details
#broadcast(clear) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/cable_ready/channel.rb', line 16 def broadcast(clear) operations.select! { |_, list| list.present? } operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) } ActionCable.server.broadcast identifier, "cableReady" => true, "operations" => operations reset if clear end |
#broadcast_to(model, clear) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/cable_ready/channel.rb', line 23 def broadcast_to(model, clear) operations.select! { |_, list| list.present? } operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) } identifier.broadcast_to model, "cableReady" => true, "operations" => operations reset if clear end |