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
methodto handle. - .dispatches ⇒ Object
- .inherited(sub) ⇒ Object
Instance Method Summary collapse
- #begin_list(name, options = {}) ⇒ Object
- #dispatches ⇒ Object
- #end_list ⇒ Object
-
#initialize(presenter) ⇒ Collector
constructor
A new instance of Collector.
- #initialize_copy(original) ⇒ Object
- #item(obj, options = {}) ⇒ Object
- #items(*objs) ⇒ Object
- #open_list(name, options = {}) ⇒ Object
Constructor Details
#initialize(presenter) ⇒ Collector
Returns a new instance of Collector.
186 187 188 189 |
# File 'lib/command-set/results.rb', line 186 def initialize(presenter) @presenter = presenter @nesting = [] 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.
252 253 254 255 |
# File 'lib/command-set/results.rb', line 252 def self.dispatch(method, &block) @dispatches[method] = true define_method(method, &block) end |
.dispatches ⇒ Object
242 243 244 |
# File 'lib/command-set/results.rb', line 242 def self.dispatches @dispatches.keys end |
.inherited(sub) ⇒ Object
238 239 240 |
# File 'lib/command-set/results.rb', line 238 def self.inherited(sub) sub.instance_variable_set("@dispatches", @dispatches.dup) end |
Instance Method Details
#begin_list(name, options = {}) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/command-set/results.rb', line 211 def begin_list( name, ={} ) @nesting.push(name) @presenter.begin_list(@nesting.dup, ) if block_given? yield end_list end end |
#dispatches ⇒ Object
246 247 248 |
# File 'lib/command-set/results.rb', line 246 def dispatches self.class.dispatches end |
#end_list ⇒ Object
231 232 233 234 |
# File 'lib/command-set/results.rb', line 231 def end_list @presenter.end_list(@nesting.dup) @nesting.pop end |
#initialize_copy(original) ⇒ Object
191 192 193 194 |
# File 'lib/command-set/results.rb', line 191 def initialize_copy(original) @presenter = original.instance_variable_get("@presenter") @nesting = original.instance_variable_get("@nesting").dup end |
#item(obj, options = {}) ⇒ Object
207 208 209 |
# File 'lib/command-set/results.rb', line 207 def item( obj, ={} ) @presenter.item(@nesting.dup + [obj], ) end |
#items(*objs) ⇒ Object
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/command-set/results.rb', line 196 def items(*objs) if Hash === objs.last = objs.pop else = {} end objs.each do |obj| item(obj, ) end end |
#open_list(name, options = {}) ⇒ Object
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/command-set/results.rb', line 220 def open_list(name, ={}) @nesting.push(name) unless @presenter.list_open?(@nesting) @presenter.begin_list(@nesting.dup, ) end if block_given? yield end_list end end |