Sha256: 76592da5a31181480293e5d3fca4d1bcbcc4edc26519fb01e5cb24930e72223b

Contents?: true

Size: 1.12 KB

Versions: 23

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

require 'state_machine'

module Punchblock
  class CommandNode < RayoNode
    def self.new(options = {})
      super().tap do |new_node|
        new_node.target_call_id = options[:target_call_id]
        new_node.target_mixer_name = options[:target_mixer_name]
        new_node.component_id = options[:component_id]
      end
    end

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

    state_machine :state, :initial => :new do
      event :request do
        transition :new => :requested
      end

      event :execute do
        transition :requested => :executing
      end

      event :complete do
        transition :executing => :complete
      end
    end

    def write_attr(*args)
      raise StandardError, "Cannot alter attributes of a requested command" unless new?
      super
    end

    def response(timeout = nil)
      @response.resource timeout
    end

    def response=(other)
      return if @response.set_yet?
      @response.resource = other
      execute!
    end

    def inspect_attributes
      super + [:state_name]
    end
  end # CommandNode
end # Punchblock

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
punchblock-1.9.4 lib/punchblock/command_node.rb
punchblock-1.9.3 lib/punchblock/command_node.rb
punchblock-1.9.2 lib/punchblock/command_node.rb
punchblock-1.9.1 lib/punchblock/command_node.rb
punchblock-1.9.0 lib/punchblock/command_node.rb
punchblock-1.8.2 lib/punchblock/command_node.rb
punchblock-1.8.1 lib/punchblock/command_node.rb
punchblock-1.8.0 lib/punchblock/command_node.rb
punchblock-1.7.1 lib/punchblock/command_node.rb
punchblock-1.7.0 lib/punchblock/command_node.rb
punchblock-1.6.1 lib/punchblock/command_node.rb
punchblock-1.6.0 lib/punchblock/command_node.rb
punchblock-1.5.3 lib/punchblock/command_node.rb
punchblock-1.5.2 lib/punchblock/command_node.rb
punchblock-1.5.1 lib/punchblock/command_node.rb
punchblock-1.5.0 lib/punchblock/command_node.rb
punchblock-1.4.1 lib/punchblock/command_node.rb
punchblock-1.4.0 lib/punchblock/command_node.rb
punchblock-1.3.0 lib/punchblock/command_node.rb
punchblock-1.2.0 lib/punchblock/command_node.rb