Class: Appfuel::Domain::EntityCollection
- Inherits:
-
Object
- Object
- Appfuel::Domain::EntityCollection
- Includes:
- Enumerable
- Defined in:
- lib/appfuel/domain/entity_collection.rb
Overview
Currently this only answers the use case where a collection of active record models are converted into a collection of domain entities via a entity loader.
NOTE: There is no ability yet to add or track the entity state
Instance Attribute Summary collapse
-
#domain_basename ⇒ Object
readonly
Returns the value of attribute domain_basename.
-
#domain_name ⇒ Object
readonly
Returns the value of attribute domain_name.
-
#entity_loader ⇒ Object
Returns the value of attribute entity_loader.
Instance Method Summary collapse
- #all ⇒ Object
- #collection? ⇒ Boolean
- #each ⇒ Object
- #entity_loader? ⇒ Boolean
- #first ⇒ Object
- #global? ⇒ Boolean
-
#initialize(domain_name, entity_loader = nil) ⇒ EntityCollection
constructor
A new instance of EntityCollection.
- #pager ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(domain_name, entity_loader = nil) ⇒ EntityCollection
Returns a new instance of EntityCollection.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/appfuel/domain/entity_collection.rb', line 13 def initialize(domain_name, entity_loader = nil) unless Types.key?(domain_name) fail "#{domain_name} is not a registered type" end @pager = nil @list = [] @loaded = false parts = domain_name.split('.') @domain_name = domain_name @domain_basename = parts.last @is_global = parts.size == 1 self.entity_loader = entity_loader if entity_loader end |
Instance Attribute Details
#domain_basename ⇒ Object (readonly)
Returns the value of attribute domain_basename.
11 12 13 |
# File 'lib/appfuel/domain/entity_collection.rb', line 11 def domain_basename @domain_basename end |
#domain_name ⇒ Object (readonly)
Returns the value of attribute domain_name.
11 12 13 |
# File 'lib/appfuel/domain/entity_collection.rb', line 11 def domain_name @domain_name end |
#entity_loader ⇒ Object
Returns the value of attribute entity_loader.
11 12 13 |
# File 'lib/appfuel/domain/entity_collection.rb', line 11 def entity_loader @entity_loader end |
Instance Method Details
#all ⇒ Object
38 39 40 41 |
# File 'lib/appfuel/domain/entity_collection.rb', line 38 def all load_entities @list end |
#collection? ⇒ Boolean
30 31 32 |
# File 'lib/appfuel/domain/entity_collection.rb', line 30 def collection? true end |
#each ⇒ Object
48 49 50 51 52 53 |
# File 'lib/appfuel/domain/entity_collection.rb', line 48 def each load_entities return @list.each unless block_given? @list.each {|entity| yield entity} end |
#entity_loader? ⇒ Boolean
68 69 70 |
# File 'lib/appfuel/domain/entity_collection.rb', line 68 def entity_loader? !@entity_loader.nil? end |
#first ⇒ Object
43 44 45 46 |
# File 'lib/appfuel/domain/entity_collection.rb', line 43 def first load_entities @list.first end |
#global? ⇒ Boolean
34 35 36 |
# File 'lib/appfuel/domain/entity_collection.rb', line 34 def global? @is_global end |
#pager ⇒ Object
55 56 57 58 |
# File 'lib/appfuel/domain/entity_collection.rb', line 55 def pager load_entities @pager end |
#to_a ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/appfuel/domain/entity_collection.rb', line 60 def to_a list = [] each do |entity| list << entity.to_h end list end |