Class: ActiveOperator::Operation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_operator/operation.rb

Instance Method Summary collapse

Instance Method Details

#errored!Object



41
42
43
# File 'lib/active_operator/operation.rb', line 41

def errored!
  update!(errored_at: Time.current)
end

#errored?Boolean

Returns:

  • (Boolean)


11
# File 'lib/active_operator/operation.rb', line 11

def errored?   = errored_at?

#performObject



13
14
15
16
17
18
19
# File 'lib/active_operator/operation.rb', line 13

def perform
  request!
  process!
rescue
  errored!
  raise
end

#perform_laterObject



21
22
23
# File 'lib/active_operator/operation.rb', line 21

def perform_later
  ActiveOperator::PerformOperationJob.perform_later(self)
end

#processObject

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/active_operator/operation.rb', line 49

def process
  raise NotImplementedError, "Operations must implement the `process` method"
end

#process!Object



31
32
33
34
35
36
37
38
39
# File 'lib/active_operator/operation.rb', line 31

def process!
  return false if !received?
  return false if processed?

  ActiveRecord::Base.transaction do
    process
    update!(processed_at: Time.current)
  end
end

#processed?Boolean

Returns:

  • (Boolean)


10
# File 'lib/active_operator/operation.rb', line 10

def processed? = processed_at?

#received?Boolean

Returns:

  • (Boolean)


9
# File 'lib/active_operator/operation.rb', line 9

def received?  = received_at?

#requestObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/active_operator/operation.rb', line 45

def request
  raise NotImplementedError, "Operations must implement the `request` method"
end

#request!Object



25
26
27
28
29
# File 'lib/active_operator/operation.rb', line 25

def request!
  return false if received?

  update!(response: request, received_at: Time.current)
end