Class: Cases::Case
- Inherits:
-
Object
- Object
- Cases::Case
- Defined in:
- lib/cases/case.rb
Instance Attribute Summary collapse
-
#action_block ⇒ Object
readonly
Returns the value of attribute action_block.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #execute(object, result) ⇒ Object
-
#initialize(method, event, options = {}, &action_block) ⇒ Case
constructor
A new instance of Case.
Constructor Details
#initialize(method, event, options = {}, &action_block) ⇒ Case
Returns a new instance of Case.
10 11 12 13 14 15 16 17 |
# File 'lib/cases/case.rb', line 10 def initialize(method, event, = {}, &action_block) @method = method @event = event @options = @action_block = action_block register end |
Instance Attribute Details
#action_block ⇒ Object (readonly)
Returns the value of attribute action_block.
4 5 6 |
# File 'lib/cases/case.rb', line 4 def action_block @action_block end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
4 5 6 |
# File 'lib/cases/case.rb', line 4 def event @event end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/cases/case.rb', line 4 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/cases/case.rb', line 4 def @options end |
#result ⇒ Object
Returns the value of attribute result.
3 4 5 |
# File 'lib/cases/case.rb', line 3 def result @result end |
Class Method Details
.all ⇒ Object
6 7 8 |
# File 'lib/cases/case.rb', line 6 def self.all @_all ||= {} end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 22 |
# File 'lib/cases/case.rb', line 19 def ==(other) method == other.method && event == other.event end |
#execute(object, result) ⇒ Object
24 25 26 27 28 |
# File 'lib/cases/case.rb', line 24 def execute(object, result) return if !result.send(event) self.result = action_block.call([:on_self] ? object : result) end |