Module: Estate::Logic::ActiveRecord::SpecificLogic

Defined in:
lib/estate/logic/active_record/specific_logic.rb

Class Method Summary collapse

Class Method Details

.add_error(instance, message, attribute: :base) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/estate/logic/active_record/specific_logic.rb', line 9

def add_error(instance, message, attribute: :base)
  if config_for(instance)[:raise_on_error]
    exception_message = attribute == :base ? message : "#{attribute}: #{message}"
    raise(StandardError, exception_message)
  else
    instance.errors.add(attribute, message) unless instance.errors[attribute].include?(message)
  end
end

.get_states(instance) ⇒ Object



18
19
20
21
22
# File 'lib/estate/logic/active_record/specific_logic.rb', line 18

def get_states(instance)
  from_state = instance.public_send("#{config_for(instance)[:column_name]}_was")
  to_state = instance.public_send(config_for(instance)[:column_name])
  [from_state, to_state]
end