Class: Transitions::State

Inherits:
Object
  • Object
show all
Defined in:
lib/transitions/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ State

Returns a new instance of State.



5
6
7
8
9
10
11
# File 'lib/transitions/state.rb', line 5

def initialize(name, options = {})
  @name = name
  if machine = options.delete(:machine)
    define_state_query_method(machine)
  end
  update(options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/transitions/state.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/transitions/state.rb', line 3

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/transitions/state.rb', line 13

def ==(other)
  if other.is_a? Symbol
    name == other
  else
    name == other.name
  end
end

#call_action(action, record) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/transitions/state.rb', line 21

def call_action(action, record)
  action = @options[action]
  case action
  when Symbol, String
    record.send(action)
  when Proc
    action.call(record)
  end
end

#display_nameObject



31
32
33
# File 'lib/transitions/state.rb', line 31

def display_name
  @display_name ||= name.to_s.tr('_', ' ').capitalize
end

#for_selectObject



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

def for_select
  [display_name, name.to_s]
end

#update(options = {}) ⇒ Object



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

def update(options = {})
  @display_name = options.delete(:display) if options.key?(:display)
  @options = options
  self
end