Module: Jbr::Listable

Includes:
Enumerable
Included in:
Jobs, Visits
Defined in:
lib/jbr/listable.rb

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

Instance Method Details

#eachObject

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(&)

#idsArray<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.

Returns:

  • (Array<String>)

    every ID in the list, every page of them read.



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.

Parameters:

  • within (ActiveSupport::Duration, Numeric, nil) (defaults to: nil)

    how far back to look, or nil for as far back as the account goes.

Returns:

  • (Listable)

    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.

Parameters:

  • within (ActiveSupport::Duration, Numeric, nil) (defaults to: nil)

    how far ahead to look, or nil for as far ahead as the account is scheduled.

Returns:

  • (Listable)

    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