Class: Jsm::EventExecutor::ActiveModel

Inherits:
Base
  • Object
show all
Defined in:
lib/jsm/event_executor/active_model.rb

Direct Known Subclasses

ActiveRecord, Mongoid

Instance Attribute Summary

Attributes inherited from Base

#state_machine, #validators

Instance Method Summary collapse

Methods inherited from Base

#execute, #execute!, #initialize

Constructor Details

This class inherits a constructor from Jsm::EventExecutor::Base

Instance Method Details

#can_be_executed?(event, obj) ⇒ Boolean

check if the obj possible to execute the event

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/jsm/event_executor/active_model.rb', line 3

def can_be_executed?(event, obj)
  state = event.can_be_transitioning_to(obj)
  attribute_name = obj.class.state_machine.attribute_name
  obj.valid?
  if state
    validators.validate(state.to, obj)
  else
    obj.errors.add(attribute_name, 'no transitions match')
  end
  obj.errors.empty?
end