Class: Command::Results::Collector

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(presenter) ⇒ Collector

Returns a new instance of Collector.



181
182
183
184
# File 'lib/command-set/results.rb', line 181

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.



247
248
249
250
# File 'lib/command-set/results.rb', line 247

def self.dispatch(method, &block)
  @dispatches[method] = true
  define_method(method, &block)
end

.dispatchesObject



237
238
239
# File 'lib/command-set/results.rb', line 237

def self.dispatches
  @dispatches.keys
end

.inherited(sub) ⇒ Object



233
234
235
# File 'lib/command-set/results.rb', line 233

def self.inherited(sub)
  sub.instance_variable_set("@dispatches", @dispatches.dup)
end

Instance Method Details

#begin_list(name, options = {}) ⇒ Object



206
207
208
209
210
211
212
213
# File 'lib/command-set/results.rb', line 206

def begin_list( name, options={} )
  @nesting.push(name)
  @presenter.begin_list(@nesting.dup, options)
  if block_given?
    yield
    end_list
  end
end

#dispatchesObject



241
242
243
# File 'lib/command-set/results.rb', line 241

def dispatches
  self.class.dispatches
end

#end_listObject



226
227
228
229
# File 'lib/command-set/results.rb', line 226

def end_list
  @presenter.end_list(@nesting.dup)
  @nesting.pop
end

#initialize_copy(original) ⇒ Object



186
187
188
189
# File 'lib/command-set/results.rb', line 186

def initialize_copy(original)
  @presenter = original.instance_variable_get("@presenter")
  @nesting = original.instance_variable_get("@nesting").dup
end

#item(obj, options = {}) ⇒ Object



202
203
204
# File 'lib/command-set/results.rb', line 202

def item( obj, options={} )
  @presenter.item(@nesting.dup + [obj], options)
end

#items(*objs) ⇒ Object



191
192
193
194
195
196
197
198
199
200
# File 'lib/command-set/results.rb', line 191

def items(*objs)
  if Hash === objs.last
    options = objs.pop
  else
    options = {}
  end
  objs.each do |obj|
    item(obj, options)
  end
end

#open_list(name, options = {}) ⇒ Object



215
216
217
218
219
220
221
222
223
224
# File 'lib/command-set/results.rb', line 215

def open_list(name, options={})
  @nesting.push(name)
  unless @presenter.list_open?(@nesting)
    @presenter.begin_list(@nesting.dup, options)
  end
  if block_given?
    yield
    end_list
  end
end