Class: Demux::Signal

Inherits:
Object
  • Object
show all
Defined in:
lib/demux/signal.rb

Overview

All signals will inherit from Demux::Signal. A signal represent a message to be demuxed and sent to apps.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_id, account_id:, demuxer: Demux.config.default_demuxer) ⇒ Signal

Returns a new instance of Signal.


22
23
24
25
26
27
28
# File 'lib/demux/signal.rb', line 22

def initialize(object_id,
               account_id:,
               demuxer: Demux.config.default_demuxer)
  @object_id = Integer(object_id)
  @account_id = 
  @demuxer = demuxer
end

Class Attribute Details

.object_classObject (readonly)

Returns the value of attribute object_class


10
11
12
# File 'lib/demux/signal.rb', line 10

def object_class
  @object_class
end

.signal_nameObject (readonly)

Returns the value of attribute signal_name


10
11
12
# File 'lib/demux/signal.rb', line 10

def signal_name
  @signal_name
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id


7
8
9
# File 'lib/demux/signal.rb', line 7

def 
  @account_id
end

Class Method Details

.attributes(attr) ⇒ Object


12
13
14
15
# File 'lib/demux/signal.rb', line 12

def attributes(attr)
  @object_class = attr.fetch(:object_class)
  @signal_name = attr.fetch(:signal_name)
end

Instance Method Details

#objectObject


30
31
32
# File 'lib/demux/signal.rb', line 30

def object
  @object ||= self.class.object_class.find(@object_id)
end

#payload_for(action) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/demux/signal.rb', line 34

def payload_for(action)
  if respond_to?("#{action}_payload")
    public_send("#{action}_payload")
  else
    payload
  end
end

#send(action) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/demux/signal.rb', line 42

def send(action)
  @demuxer.new(
    SignalAttributes.new(
      account_id: @account_id,
      action: String(action),
      object_id: @object_id,
      signal_class: self.class.name
    )
  ).resolve

  self
end

#signal_nameObject


18
19
20
# File 'lib/demux/signal.rb', line 18

def signal_name
  self.class.signal_name
end