Sha256: fc878120f87f6a8862a5135865b4f1197190dd6c1e6666fce468422bbaecba6a

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

module StateFu
  class Sprocket # Abstract Superclass of State & Event
    include StateFu::Helper # define apply!

    attr_reader :machine, :name, :options, :hooks

    def initialize(machine, name, options={})
      @machine = machine
      @name    = name.to_sym
      @options = options.symbolize_keys!
      @hooks   = StateFu::Hooks.for( self )
    end

    # sneaky way to make some comparisons / duck typing a bit cleaner
    alias_method :to_sym,  :name

    def add_hook slot, name, value
      @hooks[slot.to_sym] << [name.to_sym, value]
    end

    def lathe(options={}, &block)
      StateFu::Lathe.new( machine, self, options, &block )
    end

    def deep_copy
      raise NotImeplementedError # abstract
    end

    def to_s
      "#<#{self.class}::#{self.object_id} @name=#{name.inspect}>"
    end

    def []v
      options[v]
    end

    def []=v,k
      options[v]=k
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
davidlee-state-fu-0.3.1 lib/state_fu/sprocket.rb