Module: Jbr::Listable
Overview
What a list of records answers, and how much of an account it costs to ask. Jobber prices a query by the page it asks for and by what every row of that page carries, so a list is read either as records or as the IDs alone, each with a page sized to what it carries.
Constant Summary collapse
- PAGE =
Records a page, not forty and not a hundred: what an includes brings back is charged for on top of every row of it, so a page of jobs carrying their lines, their property and its client priced past what a bucket holds. Half the page costs half the query and loses nothing, since a walk simply reads more pages.
20- IDS_PAGE =
IDs a page, which the same budget affords five times over where a row carries one field and no nesting at all.
100
Instance Method Summary collapse
-
#each ⇒ Object
Every record the list is narrowed to, oldest first.
-
#ids ⇒ Array<String>
The ID Jobber files each record under, and nothing else about it: the cheapest question an account can be walked with, and the one to ask where every record is then read on its own through #find.
-
#past(within = nil) ⇒ Listable
The same list, narrowed to what started before now.
-
#upcoming(within = nil) ⇒ Listable
The same list, narrowed to what is scheduled from now on.
Instance Method Details
#each ⇒ Object
Every record the list is narrowed to, oldest first. Nothing is read until the walk starts, and a page is read only once the one before it runs out.
20 |
# File 'lib/jbr/listable.rb', line 20 def each(&) = walk(page).each(&) |
#ids ⇒ Array<String>
The ID Jobber files each record under, and nothing else about it: the cheapest question an account can be walked with, and the one to ask where every record is then read on its own through #find.
42 |
# File 'lib/jbr/listable.rb', line 42 def ids = walk(ids_page).map(&:id) |
#past(within = nil) ⇒ Listable
Returns the same list, narrowed to what started before now.
33 34 35 36 |
# File 'lib/jbr/listable.rb', line 33 def past(within = nil) now = Time.now narrowed before: now, after: (now - within if within) end |
#upcoming(within = nil) ⇒ Listable
Returns the same list, narrowed to what is scheduled from now on.
25 26 27 28 |
# File 'lib/jbr/listable.rb', line 25 def upcoming(within = nil) now = Time.now narrowed after: now, before: (now + within if within) end |