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 = true) ⇒ Object
- #broadcast_to(model, clear = true) ⇒ Object
- #channel_broadcast(clear) ⇒ Object
- #channel_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 = true) ⇒ Object
30 31 32 |
# File 'lib/cable_ready/channel.rb', line 30 def broadcast(clear = true) CableReady::Channels.instance.broadcast(identifier, clear: clear) end |
#broadcast_to(model, clear = true) ⇒ Object
34 35 36 |
# File 'lib/cable_ready/channel.rb', line 34 def broadcast_to(model, clear = true) CableReady::Channels.instance.broadcast_to(model, identifier, clear: clear) end |
#channel_broadcast(clear) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/cable_ready/channel.rb', line 16 def channel_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 |
#channel_broadcast_to(model, clear) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/cable_ready/channel.rb', line 23 def channel_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 |