Class: Caser::Action
Instance Attribute Summary collapse
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
Instance Method Summary collapse
- #emit(event) ⇒ Object
- #errors ⇒ Object
- #fail! ⇒ Object
-
#initialize(*params) {|@_callbacks = Callbacks.new| ... } ⇒ Action
constructor
A new instance of Action.
- #process ⇒ Object
- #processed! ⇒ Object
- #processed? ⇒ Boolean
- #set_outcome(outcome) ⇒ Object
- #succeed! ⇒ Object
- #success? ⇒ Boolean
Constructor Details
Instance Attribute Details
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
7 8 9 |
# File 'lib/caser/action.rb', line 7 def outcome @outcome end |
Instance Method Details
#emit(event) ⇒ Object
46 47 48 49 |
# File 'lib/caser/action.rb', line 46 def emit(event) changed notify_observers(event) end |
#errors ⇒ Object
42 43 44 |
# File 'lib/caser/action.rb', line 42 def errors @_errors ||= [] end |
#fail! ⇒ Object
26 27 28 |
# File 'lib/caser/action.rb', line 26 def fail! @_callbacks.on_failure(self) if @_callbacks end |
#process ⇒ Object
15 16 17 18 19 20 |
# File 'lib/caser/action.rb', line 15 def process processed! do_process success? ? succeed! : fail! self end |
#processed! ⇒ Object
30 31 32 |
# File 'lib/caser/action.rb', line 30 def processed! @_processed = true end |
#processed? ⇒ Boolean
34 35 36 |
# File 'lib/caser/action.rb', line 34 def processed? @_processed end |
#set_outcome(outcome) ⇒ Object
51 52 53 |
# File 'lib/caser/action.rb', line 51 def set_outcome(outcome) @outcome = outcome end |
#succeed! ⇒ Object
22 23 24 |
# File 'lib/caser/action.rb', line 22 def succeed! @_callbacks.on_success(self) if @_callbacks end |
#success? ⇒ Boolean
38 39 40 |
# File 'lib/caser/action.rb', line 38 def success? processed? && errors.empty? end |