Class: Statesman::Callback
- Inherits:
-
Object
- Object
- Statesman::Callback
- Defined in:
- lib/statesman/callback.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #applies_to?(options = { from: nil, to: nil }) ⇒ Boolean
- #call(*args) ⇒ Object
-
#initialize(options = { from: nil, to: nil, callback: nil }) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(options = { from: nil, to: nil, callback: nil }) ⇒ Callback
Returns a new instance of Callback.
11 12 13 14 15 16 17 18 19 |
# File 'lib/statesman/callback.rb', line 11 def initialize( = { from: nil, to: nil, callback: nil }) unless [:callback].respond_to?(:call) raise InvalidCallbackError, "No callback passed" end @from = [:from] @to = Array([:to]) @callback = [:callback] end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
9 10 11 |
# File 'lib/statesman/callback.rb', line 9 def callback @callback end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
7 8 9 |
# File 'lib/statesman/callback.rb', line 7 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
8 9 10 |
# File 'lib/statesman/callback.rb', line 8 def to @to end |
Instance Method Details
#applies_to?(options = { from: nil, to: nil }) ⇒ Boolean
25 26 27 |
# File 'lib/statesman/callback.rb', line 25 def applies_to?( = { from: nil, to: nil }) matches([:from], [:to]) end |
#call(*args) ⇒ Object
21 22 23 |
# File 'lib/statesman/callback.rb', line 21 def call(*args) callback.call(*args) end |