Class: Zn::Dataset
Overview
Holds repo, associators and performs aggregate operations
Instance Attribute Summary collapse
-
#associators ⇒ Object
readonly
Returns the value of attribute associators.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #add_associator(name, associator) ⇒ Object
- #associate(entities) ⇒ Object
- #associations(entity) ⇒ Object
-
#initialize(repo) ⇒ Dataset
constructor
A new instance of Dataset.
- #keys ⇒ Object
Constructor Details
#initialize(repo) ⇒ Dataset
Returns a new instance of Dataset.
12 13 14 15 |
# File 'lib/zn/dataset.rb', line 12 def initialize(repo) @repo = repo @associators = {} end |
Instance Attribute Details
#associators ⇒ Object (readonly)
Returns the value of attribute associators.
10 11 12 |
# File 'lib/zn/dataset.rb', line 10 def associators @associators end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/zn/dataset.rb', line 10 def repo @repo end |
Instance Method Details
#add_associator(name, associator) ⇒ Object
17 18 19 |
# File 'lib/zn/dataset.rb', line 17 def add_associator(name, associator) @associators[name] = associator end |
#associate(entities) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/zn/dataset.rb', line 37 def associate(entities) return enum_for(:associate, entities) unless block_given? entities.each do |entity| yield entity, associations(entity) end end |
#associations(entity) ⇒ Object
31 32 33 34 35 |
# File 'lib/zn/dataset.rb', line 31 def associations(entity) associators.each_with_object({}) do |(name, associator), hash| hash[name] = associator.associate(entity) end end |
#keys ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/zn/dataset.rb', line 21 def keys keys = Set.new repo.all.each do |entity| keys = keys.merge entity.keys end keys.to_a end |