Module: ActiveRepository::Finders

Included in:
Base
Defined in:
lib/active_repository/finders.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ Object

Searches for an object containing the id in #id



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_repository/finders.rb', line 5

def find(id)
  begin
    if repository?
      super(id)
    else
      serialize!(PersistenceAdapter.find(self, id))
    end
  rescue Exception => e
    message = "Couldn't find #{self} with ID=#{id}"
    message = "Couldn't find all #{self} objects with IDs (#{id.join(', ')})" if id.is_a?(Array)

    raise ActiveHash::RecordNotFound.new(message)
  end
end

#firstObject

Returns first persisted object



21
22
23
# File 'lib/active_repository/finders.rb', line 21

def first
  repository? ? super : get(:first)
end

#lastObject

Returns last persisted object



26
27
28
# File 'lib/active_repository/finders.rb', line 26

def last
  repository? ? super : get(:last)
end