Module: SparkApi::Models::Finders

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
18
# File 'lib/spark_api/models/finders.rb', line 7

def find(*arguments)
  scope = arguments.slice!(0)
  options = arguments.slice!(0) || {}
  case scope
    when nil    then raise ArgumentError, "Argument for find() can't be nil"
    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



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

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

#first(*arguments) ⇒ Object



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

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

#last(*arguments) ⇒ Object



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

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