Class: Yummi::GroupedComponent
- Inherits:
-
Object
- Object
- Yummi::GroupedComponent
- Defined in:
- lib/yummi.rb
Overview
A class to group components and blocks
Instance Method Summary collapse
-
#<<(component = nil, &block) ⇒ Object
Adds a new component.
-
#call(*args) ⇒ Object
Calls the added components by sending the configured message and the given args.
-
#initialize(params = {}) ⇒ GroupedComponent
constructor
Creates a new GroupedComponent.
Constructor Details
#initialize(params = {}) ⇒ GroupedComponent
Creates a new GroupedComponent
Args
params
-
Hash parameters:
- call_all: indicates if all components must be called. For use if the return should be ignored - message: the message to send. Defaults to :call
215 216 217 218 219 |
# File 'lib/yummi.rb', line 215 def initialize (params = {}) @components = [] @call_all = params[:call_all] @message = (params[:message] or :call) end |
Instance Method Details
#<<(component = nil, &block) ⇒ Object
Adds a new component
222 223 224 |
# File 'lib/yummi.rb', line 222 def << (component = nil, &block) @components << (component or block) end |
#call(*args) ⇒ Object
Calls the added components by sending the configured message and the given args.
229 230 231 232 233 234 235 236 |
# File 'lib/yummi.rb', line 229 def call (*args) result = nil @components.each do |component| break if result and not @call_all result = component.send @message, *args end result end |