Class: AASM::Core::Invokers::BaseInvoker
- Inherits:
-
Object
- Object
- AASM::Core::Invokers::BaseInvoker
- Defined in:
- lib/aasm/core/invokers/base_invoker.rb
Overview
Base concrete invoker class which contain basic invoking and logging definitions
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(subject, record, args) ⇒ BaseInvoker
constructor
Initialize a new concrete invoker instance.
-
#invoke ⇒ Object
Execute concrete invoker, log the error and return result.
-
#invoke_subject ⇒ Object
Execute concrete invoker.
-
#log_failure ⇒ Object
Log failed invoking.
-
#may_invoke? ⇒ Boolean
Check if concrete invoker may be invoked for a specified subject.
-
#with_failures(failures_buffer) ⇒ Object
Collect failures to a specified buffer.
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
10 11 12 |
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10 def args @args end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
10 11 12 |
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10 def failures @failures end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
10 11 12 |
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10 def record @record end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
10 11 12 |
# File 'lib/aasm/core/invokers/base_invoker.rb', line 10 def result @result end |
#subject ⇒ Object (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
#invoke ⇒ Object
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_subject ⇒ Object
Execute concrete invoker
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_failure ⇒ Object
Log failed invoking
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
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 |