Module: Transitions::ClassMethods

Defined in:
lib/transitions.rb

Instance Method Summary collapse

Instance Method Details

#define_state_query_method(state_name) ⇒ Object


58
59
60
61
62
# File 'lib/transitions.rb', line 58

def define_state_query_method(state_name)
  name = "#{state_name}?"
  undef_method(name) if method_defined?(name)
  define_method(name) { current_state.to_s == %(#{state_name}) }
end

#inherited(klass) ⇒ Object


35
36
37
38
# File 'lib/transitions.rb', line 35

def inherited(klass)
  super
  klass.state_machines = state_machines
end

#state_machine(name = nil, options = {}, &block) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'lib/transitions.rb', line 48

def state_machine(name = nil, options = {}, &block)
  if name.is_a?(Hash)
    options = name
    name    = nil
  end
  name ||= :default
  state_machines[name] ||= Machine.new(self, name)
  block ? state_machines[name].update(options, &block) : state_machines[name]
end

#state_machinesObject


40
41
42
# File 'lib/transitions.rb', line 40

def state_machines
  @state_machines ||= {}
end

#state_machines=(value) ⇒ Object


44
45
46
# File 'lib/transitions.rb', line 44

def state_machines=(value)
  @state_machines = value ? value.dup : nil
end