Module: StateMachines::Machine::Integration

Included in:
StateMachines::Machine
Defined in:
lib/state_machines/machine/integration.rb

Instance Method Summary collapse

Instance Method Details

#errors_for(_object) ⇒ Object

Gets a description of the errors for the given object. This is used to provide more detailed information when an InvalidTransition exception is raised.



14
15
16
# File 'lib/state_machines/machine/integration.rb', line 14

def errors_for(_object)
  ''
end

#generate_message(name, values = []) ⇒ Object

Generates a user-friendly name for the given message.



24
25
26
# File 'lib/state_machines/machine/integration.rb', line 24

def generate_message(name, values = [])
  format(@messages[name] || @messages[:invalid_transition] || default_messages[name] || default_messages[:invalid_transition], state: values.first)
end

#invalidate(_object, _attribute, _message, _values = []) ⇒ Object

Marks the given object as invalid with the given message.

By default, this is a no-op.



9
# File 'lib/state_machines/machine/integration.rb', line 9

def invalidate(_object, _attribute, _message, _values = []); end

#reset(_object) ⇒ Object

Resets any errors previously added when invalidating the given object.

By default, this is a no-op.



21
# File 'lib/state_machines/machine/integration.rb', line 21

def reset(_object); end

#within_transaction(object) ⇒ Object

Runs a transaction, yielding the given block.

By default, this is a no-op.



31
32
33
34
35
36
37
# File 'lib/state_machines/machine/integration.rb', line 31

def within_transaction(object, &)
  if use_transactions && respond_to?(:transaction, true)
    transaction(object, &)
  else
    yield
  end
end