Sha256: 4d32c7eafc847ce73d7f072a52930474ba4a581e91b139a4b4646d88aefa9ee6

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

require 'state_machine'

module Punchblock
  class CommandNode < RayoNode
    def self.new(options = {})
      super().tap do |new_node|
        new_node.call_id = options[:call_id]
        new_node.mixer_name = options[: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
  end # CommandNode
end # Punchblock

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
punchblock-0.9.2 lib/punchblock/command_node.rb
punchblock-0.9.1 lib/punchblock/command_node.rb
punchblock-0.9.0 lib/punchblock/command_node.rb
punchblock-0.8.4 lib/punchblock/command_node.rb
punchblock-0.8.3 lib/punchblock/command_node.rb
punchblock-0.8.2 lib/punchblock/command_node.rb
punchblock-0.8.1 lib/punchblock/command_node.rb
punchblock-0.8.0 lib/punchblock/command_node.rb
punchblock-0.7.2 lib/punchblock/command_node.rb