Module: SparkApi::Models::Finders

Included in:
Account, Activity, Contact, Listing, ListingCart, Portal, SavedSearch, SharedListing, StandardFields, VowAccount
Defined in:
lib/spark_api/models/finders.rb

Overview

Rails-like finders module

Adds the base set of finder class methods to the models that support them (not all of them do)

Instance Method Summary collapse

Instance Method Details

#find(*arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spark_api/models/finders.rb', line 7

def find(*arguments)
  scope = arguments.slice!(0)
  options = arguments.slice!(0) || {}
  case scope
    when :all   then find_every(options)
    when :first then find_every(options).first
    when :last  then find_every(options).last
    when :one   then find_every(options.merge(:_limit => 1)).first
    else             find_single(scope, options)
  end
end

#find_one(*arguments) ⇒ Object



19
20
21
# File 'lib/spark_api/models/finders.rb', line 19

def find_one(*arguments)
  find(:one, *arguments)
end

#first(*arguments) ⇒ Object



23
24
25
# File 'lib/spark_api/models/finders.rb', line 23

def first(*arguments)
  find(:first, *arguments)
end

#last(*arguments) ⇒ Object



27
28
29
# File 'lib/spark_api/models/finders.rb', line 27

def last(*arguments)
  find(:last, *arguments)
end