Class: AASM::Core::Invokers::BaseInvoker

Inherits:
Object
  • Object
show all
Defined in:
lib/aasm/core/invokers/base_invoker.rb

Overview

Base concrete invoker class which contain basic invoking and logging definitions

Direct Known Subclasses

ClassInvoker, LiteralInvoker, ProcInvoker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, record, args) ⇒ BaseInvoker

Initialize a new concrete invoker instance. NOTE that concrete invoker must be used per-subject/record

(one instance per subject/record)

Options:

subject - invoking subject comparable with this invoker record - invoking record args - arguments which will be passed to the callback



23
24
25
26
27
28
29
# File 'lib/aasm/core/invokers/base_invoker.rb', line 23

def initialize(subject, record, args)
  @subject = subject
  @record = record
  @args = args
  @result = false
  @failures = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10

def args
  @args
end

#failuresObject (readonly)

Returns the value of attribute failures.



10
11
12
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10

def failures
  @failures
end

#recordObject (readonly)

Returns the value of attribute record.



10
11
12
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10

def record
  @record
end

#resultObject (readonly)

Returns the value of attribute result.



10
11
12
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10

def result
  @result
end

#subjectObject (readonly)

Returns the value of attribute subject.



10
11
12
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10

def subject
  @subject
end

Instance Method Details

#invokeObject

Execute concrete invoker, log the error and return result



46
47
48
49
50
# File 'lib/aasm/core/invokers/base_invoker.rb', line 46

def invoke
  return unless may_invoke?
  log_failure unless invoke_subject
  result
end

#invoke_subjectObject

Execute concrete invoker

Raises:

  • (NoMethodError)


69
70
71
# File 'lib/aasm/core/invokers/base_invoker.rb', line 69

def invoke_subject
  raise NoMethodError, '"#invoke_subject" is not implemented'
end

#log_failureObject

Log failed invoking

Raises:

  • (NoMethodError)


62
63
64
# File 'lib/aasm/core/invokers/base_invoker.rb', line 62

def log_failure
  raise NoMethodError, '"#log_failure" is not implemented'
end

#may_invoke?Boolean

Check if concrete invoker may be invoked for a specified subject

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


55
56
57
# File 'lib/aasm/core/invokers/base_invoker.rb', line 55

def may_invoke?
  raise NoMethodError, '"#may_invoke?" is not implemented'
end

#with_failures(failures_buffer) ⇒ Object

Collect failures to a specified buffer

Options:

failures - failures buffer to collect failures



38
39
40
41
# File 'lib/aasm/core/invokers/base_invoker.rb', line 38

def with_failures(failures_buffer)
  @failures = failures_buffer
  self
end