Class: Alondra::Event
- Inherits:
-
Object
- Object
- Alondra::Event
- Defined in:
- lib/alondra/event.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.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
- #channel ⇒ Object
- #fire! ⇒ Object
-
#initialize(event_hash, from_json = nil, connection = nil) ⇒ Event
constructor
A new instance of Event.
- #to_json ⇒ Object
Constructor Details
#initialize(event_hash, from_json = nil, connection = nil) ⇒ Event
Returns a new instance of Event.
9 10 11 12 13 14 15 16 |
# File 'lib/alondra/event.rb', line 9 def initialize(event_hash, from_json = nil, connection = nil) @connection = connection @type = event_hash[:event].to_sym @json_encoded = from_json set_resource_from(event_hash) set_channel_from(event_hash) end |
Instance Attribute Details
#channel_name ⇒ Object (readonly)
Returns the value of attribute channel_name.
3 4 5 |
# File 'lib/alondra/event.rb', line 3 def channel_name @channel_name end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/alondra/event.rb', line 7 def connection @connection end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/alondra/event.rb', line 5 def resource @resource end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
6 7 8 |
# File 'lib/alondra/event.rb', line 6 def resource_type @resource_type end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/alondra/event.rb', line 4 def type @type end |
Instance Method Details
#as_json ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/alondra/event.rb', line 33 def as_json { :event => type, :resource_type => resource_type, :resource => resource.as_json, :channel => channel_name } end |
#channel ⇒ Object
18 19 20 |
# File 'lib/alondra/event.rb', line 18 def channel @channel ||= Channel[channel_name] end |
#fire! ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/alondra/event.rb', line 22 def fire! if connection # We are inside the Alondra Server EM.schedule do MessageQueue.instance.receive self end else MessageQueueClient.push self end end |
#to_json ⇒ Object
42 43 44 |
# File 'lib/alondra/event.rb', line 42 def to_json @json_encoded ||= ActiveSupport::JSON.encode(as_json) end |