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:
sawevents-
occur in chronological order, with no guarantee regarding timing.
closedevents-
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(list_path, options = {}) ⇒ Object
- #create_collector ⇒ Object
- #done ⇒ Object
- #end_list(list_path) ⇒ Object
-
#initialize ⇒ Presenter
constructor
A new instance of Presenter.
- #item(item_path, options = {}) ⇒ Object
- #leading_edge?(list) ⇒ Boolean
- #list_open?(list_path) ⇒ Boolean
-
#output ⇒ Object
Returns the current list of results.
- #register_formatter(formatter) ⇒ Object
Constructor Details
#initialize ⇒ Presenter
297 298 299 300 301 |
# File 'lib/command-set/results.rb', line 297 def initialize @results = List.new("") @leading_edge = @results @formatters = [] end |
Instance Method Details
#begin_list(list_path, options = {}) ⇒ Object
327 328 329 330 331 332 333 334 335 336 |
# File 'lib/command-set/results.rb', line 327 def begin_list( list_path, ={} ) list = list_path.pop home = get_collection(list_path) list = List.new(list) list. = home..merge() list.depth = list_path.length notify(:saw_begin, list) home.add(list) advance_leading_edge end |
#create_collector ⇒ Object
303 304 305 |
# File 'lib/command-set/results.rb', line 303 def create_collector return Collector.new(self) end |
#done ⇒ Object
354 355 356 357 358 |
# File 'lib/command-set/results.rb', line 354 def done @results.close advance_leading_edge notify(:done, nil) end |
#end_list(list_path) ⇒ Object
347 348 349 350 351 352 |
# File 'lib/command-set/results.rb', line 347 def end_list( list_path ) list = get_collection( list_path ) notify(:saw_end, list) list.close advance_leading_edge end |
#item(item_path, options = {}) ⇒ Object
307 308 309 310 311 312 313 314 315 |
# File 'lib/command-set/results.rb', line 307 def item( item_path, ={} ) item = item_path.pop home = get_collection(item_path) item = home.add item item. = home..merge() item.depth = item_path.length notify(:saw, item) advance_leading_edge end |
#leading_edge?(list) ⇒ Boolean
317 318 319 |
# File 'lib/command-set/results.rb', line 317 def leading_edge?(list) return list == @leading_edge end |
#list_open?(list_path) ⇒ Boolean
338 339 340 341 342 343 344 345 |
# File 'lib/command-set/results.rb', line 338 def list_open?(list_path) begin get_collection(list_path) return true rescue Exception return false end 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.
363 364 365 |
# File 'lib/command-set/results.rb', line 363 def output @results end |
#register_formatter(formatter) ⇒ Object
321 322 323 324 325 |
# File 'lib/command-set/results.rb', line 321 def register_formatter(formatter) @formatters << formatter formatter.notify(:start, nil) end |