Class: IronNails::View::ModelCollection
- Inherits:
-
Core::Collection
- Object
- Core::Collection
- IronNails::View::ModelCollection
- Defined in:
- lib/ironnails/view/collections.rb
Class Method Summary collapse
-
.generate_for(objects) ⇒ Object
Given a set of
objects
it will generate a collection of objects for the view model.
Instance Method Summary collapse
Methods inherited from Core::Collection
#<<, #[], #each, #initialize, #to_a
Constructor Details
This class inherits a constructor from IronNails::Core::Collection
Class Method Details
.generate_for(objects) ⇒ Object
Given a set of objects
it will generate a collection of objects for the view model
102 103 104 105 106 107 108 |
# File 'lib/ironnails/view/collections.rb', line 102 def generate_for(objects) models = new objects.each do |k, v| models << { k => v } end models end |
Instance Method Details
#add_model(model) ⇒ Object
87 88 89 90 |
# File 'lib/ironnails/view/collections.rb', line 87 def add_model(model) key = model.keys[0] has_model?(model) ? get_model(model)[key] = model[key] : @items << model end |
#get_model(model) ⇒ Object
92 93 94 95 96 |
# File 'lib/ironnails/view/collections.rb', line 92 def get_model(model) @items.find do |m| model.keys[0] == m.keys[0] end end |
#has_model?(model) ⇒ Boolean
83 84 85 |
# File 'lib/ironnails/view/collections.rb', line 83 def has_model?(model) !get_model(model).nil? end |