Class: Shamu::Entities::List
- Inherits:
-
Object
- Object
- Shamu::Entities::List
- Includes:
- Enumerable
- Defined in:
- lib/shamu/entities/list.rb
Overview
A list of Entity records.
Direct Known Subclasses
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerate through each of the entities in the list.
-
#get(key, field: key_attribute) ⇒ Entities::Entity
Get an entity by it's primary key.
-
#initialize(entities) ⇒ List
constructor
A new instance of List.
-
#paged? ⇒ Boolean
See PagedList for paged implementation.
Constructor Details
#initialize(entities) ⇒ List
Returns a new instance of List.
9 10 11 12 |
# File 'lib/shamu/entities/list.rb', line 9 def initialize( entities ) fail ArgumentError, "missing entities" if entities.nil? @raw_entities = entities end |
Instance Method Details
#each(&block) ⇒ Object
Enumerate through each of the entities in the list.
15 16 17 |
# File 'lib/shamu/entities/list.rb', line 15 def each( &block ) entities.each( &block ) end |
#get(key, field: key_attribute) ⇒ Entities::Entity
Get an entity by it's primary key.
35 36 37 38 39 40 41 42 43 |
# 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? ⇒ Boolean
See PagedList for paged implementation.
26 27 28 |
# File 'lib/shamu/entities/list.rb', line 26 def paged? false end |