class Shamu::Entities::List
A list of {Entities::Entity} records.
Attributes
raw_entities[R]
Public Class Methods
new( entities )
click to toggle source
@param [Enumerable] entities the raw list of entities.
# File lib/shamu/entities/list.rb, line 9 def initialize( entities ) fail ArgumentError, "missing entities" if entities.nil? @raw_entities = entities end
Public Instance Methods
each( &block )
click to toggle source
Enumerate through each of the entities in the list.
# File lib/shamu/entities/list.rb, line 15 def each( &block ) entities.each( &block ) end
get( key, field: key_attribute )
click to toggle source
Get an entity by it's primary key. @param [Object] key the primary key to look for. @param [Symbol] field to use as the primary key. Default :id. @return [Entities::Entity] the found entity. @raise [Shamu::NotFoundError] if the entity cannot be found.
# File lib/shamu/entities/list.rb, line 35 def get( key, field: key_attribute ) entity = if field == :id entities.find { |e| e.id == key } else entities.find { |e| e.send( field ) == key } end entity || fail( Shamu::NotFoundError ) end
paged?()
click to toggle source
@return [Boolean] true if the list represents a slice of a larger set. See {PagedList} for paged implementation.
# File lib/shamu/entities/list.rb, line 26 def paged? false end
Private Instance Methods
entities()
click to toggle source
# File lib/shamu/entities/list.rb, line 49 def entities # Array and others do not implement #lazy so allow anything that # doesn't support lazy to just enumerate directly. @entities ||= raw_entities.lazy || raw_entities end
key_attribute()
click to toggle source
# File lib/shamu/entities/list.rb, line 55 def key_attribute :id end