Module: Hcp::Queryable

Included in:
Customer, Estimate, Job
Defined in:
lib/hcp/concerns/queryable.rb

Overview

Extends a resource with the entry points that read a list of it, or one record.

Instance Method Summary collapse

Instance Method Details

#all(company_id: nil) ⇒ Relation

Returns every record of this kind the location holds.

Parameters:

  • company_id (String, nil) (defaults to: nil)

    the location to read as, where the account has several.

Returns:

  • (Relation)

    every record of this kind the location holds.



6
# File 'lib/hcp/concerns/queryable.rb', line 6

def all(company_id: nil) = Relation.new type: self, company_id: company_id

#count(company_id: nil) ⇒ Integer

Returns how many records of this kind the location holds.

Returns:

  • (Integer)

    how many records of this kind the location holds.



21
# File 'lib/hcp/concerns/queryable.rb', line 21

def count(company_id: nil) = all(company_id: company_id).count

#expandsArray<Symbol>

Returns what these bring back beside themselves where asked to.

Returns:

  • (Array<Symbol>)

    what these bring back beside themselves where asked to.



39
# File 'lib/hcp/concerns/queryable.rb', line 39

def expands = self::EXPANDS

#filtersHash

Returns what a list of these may be narrowed by.

Returns:

  • (Hash)

    what a list of these may be narrowed by.



30
# File 'lib/hcp/concerns/queryable.rb', line 30

def filters = self::FILTERS

#find(id, company_id: nil) ⇒ Resource

Returns the record Housecall Pro files under this ID.

Returns:

  • (Resource)

    the record Housecall Pro files under this ID.



27
# File 'lib/hcp/concerns/queryable.rb', line 27

def find(id, company_id: nil) = all(company_id: company_id).find(id)

#first(company_id: nil) ⇒ Resource?

Returns the first record, or nil where the location holds none.

Returns:

  • (Resource, nil)

    the first record, or nil where the location holds none.



24
# File 'lib/hcp/concerns/queryable.rb', line 24

def first(company_id: nil) = all(company_id: company_id).first

#includes(*names, company_id: nil) ⇒ Relation

Returns the records, with these brought back beside each of them.

Returns:

  • (Relation)

    the records, with these brought back beside each of them.



18
# File 'lib/hcp/concerns/queryable.rb', line 18

def includes(*names, company_id: nil) = all(company_id: company_id).includes(*names)

#limit(count, company_id: nil) ⇒ Relation

Returns at most this many records.

Returns:

  • (Relation)

    at most this many records.



15
# File 'lib/hcp/concerns/queryable.rb', line 15

def limit(count, company_id: nil) = all(company_id: company_id).limit(count)

#manyArray<Symbol>

Returns the conditions Housecall Pro takes more than one of.

Returns:

  • (Array<Symbol>)

    the conditions Housecall Pro takes more than one of.



33
# File 'lib/hcp/concerns/queryable.rb', line 33

def many = self::MANY

#order(company_id: nil, **sorts) ⇒ Relation

Returns the records in this order.

Returns:

  • (Relation)

    the records in this order.



12
# File 'lib/hcp/concerns/queryable.rb', line 12

def order(company_id: nil, **sorts) = all(company_id: company_id).order(**sorts)

#sortsArray<Symbol>

Returns what Housecall Pro will put a list of these in order of.

Returns:

  • (Array<Symbol>)

    what Housecall Pro will put a list of these in order of.



36
# File 'lib/hcp/concerns/queryable.rb', line 36

def sorts = self::SORTS

#where(company_id: nil, **conditions) ⇒ Relation

Returns the records matching these conditions.

Returns:

  • (Relation)

    the records matching these conditions.



9
# File 'lib/hcp/concerns/queryable.rb', line 9

def where(company_id: nil, **conditions) = all(company_id: company_id).where(**conditions)