Class: Command::Results::Collector
- Inherits:
-
Object
- Object
- Command::Results::Collector
- Defined in:
- lib/command-set/results.rb
Overview
Collects the events spawned by dispatchers and sends them to the presenter. Responsible for maintaining it’s own place within the larger tree, but doesn’t understand that other Collectors could be running at the same time - that’s the Presenter’s job.
Class Method Summary collapse
-
.dispatch(method, &block) ⇒ Object
Use to register an IO
method
to handle. - .dispatches ⇒ Object
- .inherited(sub) ⇒ Object
Instance Method Summary collapse
- #begin_list(name, options = {}) ⇒ Object
- #dispatches ⇒ Object
- #end_list ⇒ Object
-
#initialize(presenter, list_root) ⇒ Collector
constructor
A new instance of Collector.
- #initialize_copy(original) ⇒ Object
- #item(obj, options = {}) ⇒ Object
- #items(*objs) ⇒ Object
Constructor Details
#initialize(presenter, list_root) ⇒ Collector
Returns a new instance of Collector.
176 177 178 179 |
# File 'lib/command-set/results.rb', line 176 def initialize(presenter, list_root) @presenter = presenter @nesting = [list_root] end |
Class Method Details
.dispatch(method, &block) ⇒ Object
Use to register an IO method
to handle. The block will be passed a Collector and the arguments passed to method
.
229 230 231 232 |
# File 'lib/command-set/results.rb', line 229 def self.dispatch(method, &block) @dispatches[method] = true define_method(method, &block) end |
.dispatches ⇒ Object
219 220 221 |
# File 'lib/command-set/results.rb', line 219 def self.dispatches @dispatches.keys end |
.inherited(sub) ⇒ Object
215 216 217 |
# File 'lib/command-set/results.rb', line 215 def self.inherited(sub) sub.instance_variable_set("@dispatches", @dispatches.dup) end |
Instance Method Details
#begin_list(name, options = {}) ⇒ Object
201 202 203 204 205 206 207 |
# File 'lib/command-set/results.rb', line 201 def begin_list( name, ={} ) @nesting << @presenter.begin_list(@nesting.last, name, ) if block_given? yield end_list end end |
#dispatches ⇒ Object
223 224 225 |
# File 'lib/command-set/results.rb', line 223 def dispatches self.class.dispatches end |
#end_list ⇒ Object
209 210 211 |
# File 'lib/command-set/results.rb', line 209 def end_list @presenter.end_list(@nesting.pop) end |
#initialize_copy(original) ⇒ Object
181 182 183 184 |
# File 'lib/command-set/results.rb', line 181 def initialize_copy(original) @presenter = original.instance_variable_get("@presenter") @nesting = original.instance_variable_get("@nesting").dup end |
#item(obj, options = {}) ⇒ Object
197 198 199 |
# File 'lib/command-set/results.rb', line 197 def item( obj, ={} ) @presenter.item(@nesting.last, obj, ) end |
#items(*objs) ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/command-set/results.rb', line 186 def items(*objs) if Hash === objs.last = objs.pop else = {} end objs.each do |obj| item(obj, ) end end |