Class: DesignerNews::Model
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- DesignerNews::Model
- Defined in:
- lib/designer_news/model.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build_associations(hash, *associations) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/designer_news/model.rb', line 6 def build_associations(hash, *associations) mapping = {} associations.each do |association| mapping[association] = hash.fetch(association.to_s, {}) hash.delete(association) if mapping[association] end instance = new(hash) associations.each do |association| klass = association_to_class(association) objs = mapping[association].map { |p| klass.new(p) } instance[association.to_s] = objs end instance end |
Instance Method Details
#set_context(context_arguments = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/designer_news/model.rb', line 33 def set_context(context_arguments={}) self.context = {} context_arguments.each do |argument, value| self.context[argument] = value end self end |