Sha256: fc17e76cb6e2deef5cd5c93429e922ea1732147fb367fddce7d8104c7e6b7c65

Contents?: true

Size: 987 Bytes

Versions: 11

Compression:

Stored size: 987 Bytes

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.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

11 entries across 11 versions & 1 rubygems

Version Path
punchblock-0.7.1 lib/punchblock/command_node.rb
punchblock-0.7.0 lib/punchblock/command_node.rb
punchblock-0.6.2 lib/punchblock/command_node.rb
punchblock-0.6.1 lib/punchblock/command_node.rb
punchblock-0.6.0 lib/punchblock/command_node.rb
punchblock-0.5.1 lib/punchblock/command_node.rb
punchblock-0.5.0 lib/punchblock/command_node.rb
punchblock-0.4.3 lib/punchblock/command_node.rb
punchblock-0.4.2 lib/punchblock/command_node.rb
punchblock-0.4.1 lib/punchblock/command_node.rb
punchblock-0.4.0 lib/punchblock/command_node.rb