class DesignerNews::Model
Public Class Methods
build_associations(hash, *associations)
click to toggle source
# 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
Private Class Methods
association_to_class(association)
click to toggle source
# File lib/designer_news/model.rb, line 27 def association_to_class(association) class_name = association.to_s.chomp('s').capitalize DesignerNews.const_get(class_name) end
Public Instance Methods
set_context(context_arguments={})
click to toggle source
# 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