Module: Control::State

Defined in:
lib/control/state.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/control/state.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
  base.send :before_save, :validate_transition
  base.send :after_save, :save_transition
end

Instance Method Details

#nextObject

Get the next state

Returns:

  • next state object



75
76
77
78
# File 'lib/control/state.rb', line 75

def next
  transition = workflow.transitions.where(:from_class => self.class, :from_id => self.id).first
  transition.to if transition
end

#previousObject

Get previous state

Returns:

  • previous state object



68
69
70
71
# File 'lib/control/state.rb', line 68

def previous
  transition = workflow.transitions.where(:to_class => self.class, :to_id => self.id).first
  transition.from if transition
end

#workflowObject

Gets the workflow associated with state

Returns:

  • workflow object



62
63
64
# File 'lib/control/state.rb', line 62

def workflow
  send self.class.workflow_class.to_s.underscore if self.class.workflow_class
end