Class: Command::Results::Presenter
- Inherits:
-
Object
- Object
- Command::Results::Presenter
- Defined in:
- lib/command-set/results.rb
Overview
Gets item and list events from Collectors, and emits two kinds of events to Formatters:
saw
events-
occur in chronological order, with no guarantee regarding timing.
closed
events-
occur in tree order.
In general, saw
events are good for immediate feedback to the user, not so good in terms of making sense of things. They’re generated as soon as the relevant output element enters the system.
On the other hand, closed
events will be generated in the natural order you’d expect the output to appear in. Most Formatter subclasses use closed
events.
A list which has not received a “list_end” event from upstream will block lists later in tree order until it closes. A Formatter that listens only to closed
events can present them to the user in a way that should be reasonable, although output might be halting for any process that takes noticeable time.
Defined Under Namespace
Classes: Exception
Instance Method Summary collapse
- #begin_list(home, name, options = {}) ⇒ Object
- #create_collector ⇒ Object
- #done ⇒ Object
- #end_list(list) ⇒ Object
-
#initialize ⇒ Presenter
constructor
A new instance of Presenter.
- #item(home, value, options = {}) ⇒ Object
- #leading_edge?(list) ⇒ Boolean
-
#output ⇒ Object
Returns the current list of results.
- #register_formatter(formatter) ⇒ Object
Constructor Details
Instance Method Details
#begin_list(home, name, options = {}) ⇒ Object
304 305 306 307 308 309 310 311 |
# File 'lib/command-set/results.rb', line 304 def begin_list( home, name, ={} ) list = List.new(name) add_item(home, list, ) notify(:saw_begin, list) return list end |
#create_collector ⇒ Object
282 283 284 |
# File 'lib/command-set/results.rb', line 282 def create_collector return Collector.new(self, @results) end |
#done ⇒ Object
323 324 325 326 327 |
# File 'lib/command-set/results.rb', line 323 def done @results.close advance_leading_edge notify(:done, nil) end |
#end_list(list) ⇒ Object
313 314 315 316 317 318 319 320 321 |
# File 'lib/command-set/results.rb', line 313 def end_list( list ) @list_lock.synchronize do list.close advance_leading_edge end notify(:saw_end, list) return nil end |
#item(home, value, options = {}) ⇒ Object
295 296 297 298 299 300 301 302 |
# File 'lib/command-set/results.rb', line 295 def item( home, value, ={} ) item = ListItem.new(value) add_item(home, item, ) notify(:saw, item) return nil end |
#leading_edge?(list) ⇒ Boolean
291 292 293 |
# File 'lib/command-set/results.rb', line 291 def leading_edge?(list) return list == @leading_edge end |
#output ⇒ Object
Returns the current list of results. A particularly advanced Formatter might treat saw_*
events like notifications, and then use the List#filter functionality to discover the specifics about the item or list just closed.
333 334 335 |
# File 'lib/command-set/results.rb', line 333 def output @results end |
#register_formatter(formatter) ⇒ Object
286 287 288 289 |
# File 'lib/command-set/results.rb', line 286 def register_formatter(formatter) @formatters << formatter formatter.notify(:start, nil) end |