Class: Hcp::Relation
- Inherits:
-
Object
- Object
- Hcp::Relation
- Includes:
- Enumerable, Chainable
- Defined in:
- lib/hcp/relation.rb
Overview
Every record of one kind a Housecall Pro account holds, walked a page at a time.
Constant Summary collapse
- PAGE =
Records a page: the most Housecall Pro answers with, and more than it refuses.
200
Instance Method Summary collapse
-
#count ⇒ Integer
A page of one carries the total beside it, so this is one small read however long the list is.
-
#each(&block) ⇒ Enumerator, Relation
Nothing is read until the walk starts, and a page only once the one before it runs out.
-
#find(id) ⇒ Resource
Shadows Enumerable#find the way Active Record does: a record is reached by the ID Housecall Pro files it under, not by asking every record whether it is the one.
-
#initialize(type:, path: nil, company_id: nil, conditions: {}, sorts: {}, limit: nil, expands: []) ⇒ Relation
constructor
A new instance of Relation.
Methods included from Chainable
#includes, #limit, #order, #where
Constructor Details
#initialize(type:, path: nil, company_id: nil, conditions: {}, sorts: {}, limit: nil, expands: []) ⇒ Relation
Returns a new instance of Relation.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hcp/relation.rb', line 12 def initialize(type:, path: nil, company_id: nil, conditions: {}, sorts: {}, limit: nil, expands: []) @type = type @path = path || type.path @company_id = company_id @conditions = conditions @sorts = sorts @limit = limit @expands = end |
Instance Method Details
#count ⇒ Integer
A page of one carries the total beside it, so this is one small read however long the list is.
41 |
# File 'lib/hcp/relation.rb', line 41 def count = @count ||= [ read(@path, page_size: 1)['total_items'], @limit ].compact.min |
#each(&block) ⇒ Enumerator, Relation
Nothing is read until the walk starts, and a page only once the one before it runs out.
25 26 27 28 29 30 |
# File 'lib/hcp/relation.rb', line 25 def each(&block) return walk unless block walk.each(&block) self end |
#find(id) ⇒ Resource
Shadows Enumerable#find the way Active Record does: a record is reached by the ID Housecall Pro files it under, not by asking every record whether it is the one.
36 |
# File 'lib/hcp/relation.rb', line 36 def find(id) = record_for read("#{@path}/#{id}") |