Class: Knish::Collection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Knish::Collection
- Defined in:
- lib/knish/collection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(model) ⇒ Object (also: #<<)
- #configure(model) ⇒ Object
-
#initialize(name, parent_config) ⇒ Collection
constructor
A new instance of Collection.
- #load ⇒ Object
- #next_id ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(name, parent_config) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 9 |
# File 'lib/knish/collection.rb', line 5 def initialize(name, parent_config) super([]) @name = name @config = CollectionConfig.new(parent_config, name) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/knish/collection.rb', line 3 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/knish/collection.rb', line 3 def name @name end |
Instance Method Details
#add(model) ⇒ Object Also known as: <<
11 12 13 14 |
# File 'lib/knish/collection.rb', line 11 def add(model) configure(model) push(model) end |
#configure(model) ⇒ Object
36 37 38 39 |
# File 'lib/knish/collection.rb', line 36 def configure(model) model.config = config.member_config(model.config) model end |
#load ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/knish/collection.rb', line 22 def load clear config.generic_model_configs.each do |c| push( Member.new(config, c).loaded_model ) end self end |
#next_id ⇒ Object
32 33 34 |
# File 'lib/knish/collection.rb', line 32 def next_id config.next_id + select{|m| !m.persisted? }.size end |
#save ⇒ Object
18 19 20 |
# File 'lib/knish/collection.rb', line 18 def save each(&:save) end |