Class: Alondra::Command
- Inherits:
-
Object
- Object
- Alondra::Command
- Defined in:
- lib/alondra/command.rb
Instance Attribute Summary collapse
-
#channel_name ⇒ Object
readonly
Returns the value of attribute channel_name.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #channel ⇒ Object
- #execute! ⇒ Object
- #fire_event(event_type) ⇒ Object
-
#initialize(connection, command_hash) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(connection, command_hash) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 |
# File 'lib/alondra/command.rb', line 7 def initialize(connection, command_hash) @connection = connection @name = command_hash[:command].to_sym @channel_name = command_hash[:channel] end |
Instance Attribute Details
#channel_name ⇒ Object (readonly)
Returns the value of attribute channel_name.
5 6 7 |
# File 'lib/alondra/command.rb', line 5 def channel_name @channel_name end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/alondra/command.rb', line 4 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/alondra/command.rb', line 3 def name @name end |
Instance Method Details
#channel ⇒ Object
14 15 16 |
# File 'lib/alondra/command.rb', line 14 def channel @channel ||= Channel[channel_name] end |
#execute! ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/alondra/command.rb', line 18 def execute! case name when :subscribe then channel.subscribe @connection fire_event :subscribed when :unsubscribe then channel.unsubscribe @connection fire_event :unsubscribed end end |
#fire_event(event_type) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/alondra/command.rb', line 29 def fire_event(event_type) event_hash = { :event => event_type, :resource => @connection.session, :resource_type => @connection.session.class.name, :channel => @channel_name } Event.new(event_hash, nil, connection).fire! end |