Module: Morpheus::Mixins::Finders::ClassMethods

Defined in:
lib/morpheus/mixins/finders.rb

Instance Method Summary collapse

Instance Method Details

#allObject



34
35
36
37
# File 'lib/morpheus/mixins/finders.rb', line 34

def all
  attributes = [UrlBuilder.find_all(self), nil, {}]
  get(*attributes)
end

#find(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/morpheus/mixins/finders.rb', line 11

def find(*args)
  options = args.extract_options!
  if args.length == 1
    case args.first
    when Integer, String
      attributes = [UrlBuilder.find_one(self, args.first.to_i), nil, { :id => args.first.to_i }]
      get(*attributes)
    when Array
      attributes = UrlBuilder.find_some(self, args.first.sort).push({ :ids => args.first })
      get(*attributes)
    else
      raise ArgumentError, "Unrecognized argument (#{args.first.inspect})."
    end
  else
    attributes = UrlBuilder.find_some(self, args.sort).push({ :ids => args })
    get(*attributes)
  end
end

#firstObject



39
40
41
# File 'lib/morpheus/mixins/finders.rb', line 39

def first
  limit(1).first
end

#limit(amount) ⇒ Object



47
48
49
# File 'lib/morpheus/mixins/finders.rb', line 47

def limit(amount)
  Relation.new(self).limit(amount)
end

#page(page_number) ⇒ Object



51
52
53
# File 'lib/morpheus/mixins/finders.rb', line 51

def page(page_number)
  Relation.new(self).page(page_number)
end

#results_per_pageObject



55
56
57
# File 'lib/morpheus/mixins/finders.rb', line 55

def results_per_page
  @results_per_page || 10
end

#results_per_page=(_results_per_page) ⇒ Object



59
60
61
# File 'lib/morpheus/mixins/finders.rb', line 59

def results_per_page=(_results_per_page)
  @results_per_page = _results_per_page
end

#scopedObject



30
31
32
# File 'lib/morpheus/mixins/finders.rb', line 30

def scoped
  Relation.new(self)
end

#where(query_attributes) ⇒ Object



43
44
45
# File 'lib/morpheus/mixins/finders.rb', line 43

def where(query_attributes)
  Relation.new(self).where(query_attributes)
end