Class: Punchblock::Component::ComponentNode

Inherits:
Punchblock::CommandNode show all
Includes:
HasGuardedHandlers
Defined in:
lib/punchblock/component.rb

Instance Attribute Summary collapse

Attributes inherited from RayoNode

#call_id, #client, #component_id, #connection, #original_component

Instance Method Summary collapse

Methods inherited from Punchblock::CommandNode

new, #response, #write_attr

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, #inspect_attributes, new, register, #source

Constructor Details

#initialize(*args) ⇒ ComponentNode

Returns a new instance of ComponentNode.



17
18
19
20
21
# File 'lib/punchblock/component.rb', line 17

def initialize(*args)
  super
  @complete_event = FutureResource.new
  register_initial_handlers
end

Instance Attribute Details

#complete_eventObject

Returns the value of attribute complete_event.



15
16
17
# File 'lib/punchblock/component.rb', line 15

def complete_event
  @complete_event
end

Instance Method Details

#add_event(event) ⇒ Object



31
32
33
34
# File 'lib/punchblock/component.rb', line 31

def add_event(event)
  event.original_component = self
  trigger_handler :event, event
end

#register_event_handler(*guards, &block) ⇒ Object



36
37
38
# File 'lib/punchblock/component.rb', line 36

def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end

#register_initial_handlersObject



23
24
25
26
27
28
29
# File 'lib/punchblock/component.rb', line 23

def register_initial_handlers
  register_event_handler Event::Complete do |event|
    complete!
    complete_event.resource = event
    throw :pass
  end
end

#response=(other) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/punchblock/component.rb', line 45

def response=(other)
  if other.is_a?(Ref)
    @component_id = other.id
    client.register_component self
  end
  super
end

#stop!(options = {}) ⇒ Object

Sends an Rayo stop message for the current component

Raises:



65
66
67
68
# File 'lib/punchblock/component.rb', line 65

def stop!(options = {})
  raise InvalidActionError, "Cannot stop a #{self.class.name.split("::").last} that is not executing" unless executing?
  stop_action.tap { |action| write_action action }
end

#stop_actionStop

Create an Rayo stop message

Returns:

  • (Stop)

    an Rayo stop message



58
59
60
# File 'lib/punchblock/component.rb', line 58

def stop_action
  Stop.new :component_id => component_id, :call_id => call_id
end

#write_action(action) ⇒ Object



40
41
42
43
# File 'lib/punchblock/component.rb', line 40

def write_action(action)
  client.execute_command action, :call_id => call_id, :component_id => component_id
  action
end