Module: DataMapper::Is::StateMachine::InstanceMethods

### Home Classes Methods

### In Files

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

### Methods

- ::new
- #run_hook_if_present
- #transition!

### 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::InstanceMethods

### Public Class Methods

new(*args) click to toggle source

    # File lib/dm-is-state_machine/is/state_machine.rb, line 100
    def initialize(*args)
      super
      # ===== Run :enter hook if present =====
      return unless is_sm = model.instance_variable_get(:@is_state_machine)
      return unless machine = is_sm[:machine]
      return unless initial = machine.initial
      return unless initial_state = machine.find_state(initial)
      run_hook_if_present initial_state.options[:enter]
    end

### Public Instance Methods

run_hook_if_present(hook) click to toggle source

hook may be either a Proc or symbol

    # File lib/dm-is-state_machine/is/state_machine.rb, line 111
    def run_hook_if_present(hook)
      return unless hook
      if hook.respond_to?(:call)
        hook.call(self)
      else
        __send__(hook)
      end
    end

transition!(event_name) click to toggle source

    # File lib/dm-is-state_machine/is/state_machine.rb, line 120
    def transition!(event_name)
      machine = model.instance_variable_get(:@is_state_machine)[:machine]
      column = machine.column
      machine.current_state_name = __send__(column)
      machine.fire_event(event_name, self)
      __send__("#{column}=", machine.current_state_name)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.