Module: DataMapper::Is::StateMachine::StateDsl

### Home Classes Methods

### In Files

- lib/dm-is-state_machine/is/dsl/state_dsl.rb

### Methods

- #state

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Is
- DataMapper::Is::StateMachine
- DataMapper::Is::StateMachine::Data
- DataMapper::Is::StateMachine::Data::Event
- DataMapper::Is::StateMachine::Data::Machine
- DataMapper::Is::StateMachine::Data::State
- DataMapper::Is::StateMachine::DuplicateStates
- DataMapper::Is::StateMachine::EventConfusion
- DataMapper::Is::StateMachine::EventDsl
- DataMapper::Is::StateMachine::InstanceMethods
- DataMapper::Is::StateMachine::InvalidContext
- DataMapper::Is::StateMachine::InvalidEvent
- DataMapper::Is::StateMachine::InvalidState
- DataMapper::Is::StateMachine::NoInitialState
- DataMapper::Is::StateMachine::StateDsl

No matching classes.

# DataMapper::Is::StateMachine::StateDsl

State DSL (Domain Specific Language)

### Public Instance Methods

state(name, options = {}) click to toggle source

Define a state of the system.

Example:

    class TrafficLight
      include DataMapper::Resource
      property :id, Serial
      is :state_machine do
        state :green,  :enter => Proc.new { |o| o.log("G") }
        state :yellow, :enter => Proc.new { |o| o.log("Y") }
        state :red,    :enter => Proc.new { |o| o.log("R") }

        # event definitions go here...
      end

      def log(string)
        Merb::Logger.info(string)
      end
    end

    # File lib/dm-is-state_machine/is/dsl/state_dsl.rb, line 26
    def state(name, options = {})
      unless state_machine_context?(:is)
        raise InvalidContext, "Valid only in 'is :state_machine' block"
      end

      # ===== Setup context =====
      machine = @is_state_machine[:machine]
      state = Data::State.new(name, machine, options)
      machine.states << state
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.