Module: Kangaroo::Model::Finder

Included in:
Base
Defined in:
lib/kangaroo/model/finder.rb

Constant Summary collapse

RELATION_DELEGATES =
%w(where limit offset order select context reverse)

Instance Method Summary collapse

Instance Method Details

#allArray

Retrieve all records

Returns:

  • (Array)

    records



12
13
14
# File 'lib/kangaroo/model/finder.rb', line 12

def all
  relation.all
end

#countNumber

Count number of records

Returns:

  • (Number)


58
59
60
# File 'lib/kangaroo/model/finder.rb', line 58

def count
  count_by
end

#exists?(ids) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/kangaroo/model/finder.rb', line 37

def exists? ids
  where(:id => ids).exists?
end

#find(id) ⇒ Object #find(keyword) ⇒ Object

ActiveRecord-ish find method

Overloads:

  • #find(id) ⇒ Object

    Find a record by id

    Parameters:

    • id (Number)
  • #find(keyword) ⇒ Object

    Find all, first or last record

    Parameters:

    • keyword (String, Symbol)

      :all, :first or :last



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kangaroo/model/finder.rb', line 24

def find id_or_keyword
  case id_or_keyword
  when :all, 'all'
    all
  when :first, 'first'
    first
  when :last, 'last'
    last
  else
    super
  end
end

#firstObject

Retrieve first record

Returns:

  • record



44
45
46
# File 'lib/kangaroo/model/finder.rb', line 44

def first
  relation.first
end

#lastObject

Retrieve last record

Returns:

  • record



51
52
53
# File 'lib/kangaroo/model/finder.rb', line 51

def last
  relation.last
end