Class: StateMachina::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name, machine_name, name, metadata: {}) ⇒ State

Returns a new instance of State.



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

def initialize(model_name, machine_name, name, metadata: {})
  @model_name = model_name
  @machine_name = machine_name
  @name = name.to_s
  @metadata = 
end

Instance Attribute Details

#machineObject

Returns the value of attribute machine.



4
5
6
# File 'lib/state_machina/state.rb', line 4

def machine
  @machine
end

#machine_nameObject (readonly)

Returns the value of attribute machine_name.



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

def machine_name
  @machine_name
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



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

def model_name
  @model_name
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#before?(other_state_name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/state_machina/state.rb', line 13

def before?(other_state_name)
  return false if machine.nil?

  machine.states.before(other_state_name).map(&:name).include?(machine.current_state_name)
end

#before_inclusive?(other_state_name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/state_machina/state.rb', line 19

def before_inclusive?(other_state_name)
  return false if machine.nil?

  machine.states.before_inclusive(other_state_name).map(&:name).include?(machine.current_state_name)
end

#between?(from_state_name, to_state_name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/state_machina/state.rb', line 37

def between?(from_state_name, to_state_name)
  return false if machine.nil?

  machine.states.between(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name)
end

#between_inclusive?(from_state_name, to_state_name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/state_machina/state.rb', line 43

def between_inclusive?(from_state_name, to_state_name)
  return false if machine.nil?

  machine.states.between_inclusive(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name)
end

#past?(other_state_name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/state_machina/state.rb', line 25

def past?(other_state_name)
  return false if machine.nil?

  machine.states.past(other_state_name).map(&:name).include?(machine.current_state_name)
end

#past_inclusive?(other_state_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/state_machina/state.rb', line 31

def past_inclusive?(other_state_name)
  return false if machine.nil?

  machine.states.past_inclusive(other_state_name).map(&:name).include?(machine.current_state_name)
end