Class: Wee::AnswerDecoration
- Inherits:
-
Decoration
- Object
- Presenter
- Decoration
- Wee::AnswerDecoration
- Defined in:
- lib/wee/call_answer.rb
Overview
A Wee::AnswerDecoration is wrapped around a component that will call Component#answer. This makes it possible to use such components without the need to call them (Component#call), e.g. as child components of other components.
Defined Under Namespace
Classes: Answer
Instance Attribute Summary collapse
-
#answer_callback ⇒ Object
Returns the value of attribute answer_callback.
Attributes inherited from Decoration
Instance Method Summary collapse
-
#initialize(&answer_callback) ⇒ AnswerDecoration
constructor
A new instance of AnswerDecoration.
-
#process_callbacks(callbacks) ⇒ Object
When a component answers,
@answer_callback.call(answer)
will be executed, whereanswer
is of class Answer which includes the arguments passed to Component#answer.
Methods inherited from Decoration
#global?, #render_on, #render_presenter_on, #state
Methods inherited from Presenter
#render, #render_on, #renderer_class, #state
Constructor Details
#initialize(&answer_callback) ⇒ AnswerDecoration
Returns a new instance of AnswerDecoration.
21 22 23 24 |
# File 'lib/wee/call_answer.rb', line 21 def initialize(&answer_callback) super() @answer_callback = answer_callback end |
Instance Attribute Details
#answer_callback ⇒ Object
Returns the value of attribute answer_callback.
19 20 21 |
# File 'lib/wee/call_answer.rb', line 19 def answer_callback @answer_callback end |
Instance Method Details
#process_callbacks(callbacks) ⇒ Object
When a component answers, @answer_callback.call(answer)
will be executed, where answer
is of class Answer which includes the arguments passed to Component#answer.
31 32 33 34 35 36 37 38 |
# File 'lib/wee/call_answer.rb', line 31 def process_callbacks(callbacks) begin super rescue Answer => answer # return to the calling component @answer_callback.call(answer) end end |