Module: Transitions::ClassMethods

Defined in:
lib/transitions.rb

Instance Method Summary collapse

Instance Method Details

#define_state_query_method(state_name) ⇒ Object



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

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

#inherited(klass) ⇒ Object



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

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

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



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

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



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

def state_machines
  @state_machines ||= {}
end

#state_machines=(value) ⇒ Object



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

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