Class: Jsm::EventExecutor::ActiveRecord

Inherits:
ActiveModel show all
Defined in:
lib/jsm/event_executor/active_record.rb

Instance Attribute Summary

Attributes inherited from Base

#validators

Instance Method Summary collapse

Methods inherited from ActiveModel

#can_be_executed?

Methods inherited from Base

#can_be_executed?, #execute!, #initialize

Constructor Details

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

Instance Method Details

#execute(event, obj) ⇒ Object



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

def execute(event, obj)
  if can_be_executed?(event, obj)
    result = false
    # do transaction to prevent shit happen
    ActiveRecord::Base.transaction do
      obj.class.lock
      event.execute(obj)
      result = obj.save
    end
    result
  else
    false
  end
end