Module: Redpear::Model::Finders::ClassMethods

Defined in:
lib/redpear/model/finders.rb

Instance Method Summary collapse

Instance Method Details

#allArray<Redpear::Model>

Returns all records.

Returns:



24
25
26
# File 'lib/redpear/model/finders.rb', line 24

def all
  members.map &method(:find)
end

#countInteger

Returns the number of total records.

Returns:

  • (Integer)

    the number of total records



7
8
9
# File 'lib/redpear/model/finders.rb', line 7

def count
  members.size
end

#exists?(id) ⇒ Boolean

Returns true or false.

Parameters:

  • id (String)

    the ID to check

Returns:

  • (Boolean)

    true or false



13
14
15
# File 'lib/redpear/model/finders.rb', line 13

def exists?(id)
  !id.nil? && members.include?(id)
end

#find(id) ⇒ Redpear::Model

Returns a record, or nil when not found.

Parameters:

  • id (String)

    the ID of the record to find

Returns:



19
20
21
# File 'lib/redpear/model/finders.rb', line 19

def find(id)
  instantiate(id) if exists?(id)
end

#find_each {|record| ... } ⇒ Object

Yields:

  • over each available record

Yield Parameters:



30
31
32
33
34
# File 'lib/redpear/model/finders.rb', line 30

def find_each
  members.each do |id|
    yield find(id)
  end
end