module Denormalizer::Denormalize::InstanceMethods
Public Instance Methods
association_denormalization()
click to toggle source
# File lib/denormalizer/denormalize.rb, line 114 def association_denormalization # TODO: make sure this doesn't loop infinitely (JH 7-13-2012) # if two models have a circular association or a model has a self association, this will not work self.denormalized_associations.each do |assoc_method| assoc = self.send(assoc_method) if assoc.is_a?(Array) assoc.each do |a| a.method_denormalization end else assoc.method_denormalization end end end
method_denormalization()
click to toggle source
# File lib/denormalizer/denormalize.rb, line 87 def method_denormalization # don't even try if a new record if !new_record? # iterate over the saved methods self.denormalized_methods.each do |method_name| # run the method and save the result method_output = self.send(method_name) ? Denormalizer::MethodOutput::TrueOutput : Denormalizer::MethodOutput::FalseOutput # find a match then create or update based on success # TODO: refactor this entire section to metho on Denormalizer::MethodOutput (JH 7-13-2012) saved_output = Denormalizer::MethodOutput.by_object_and_method_name(self, method_name, self.denormalization_class).first if saved_output.nil? attributes = { :denormalized_object_type => self.denormalization_class, :denormalized_object_id => self.id, :denormalized_object_method => method_name, :method_output => method_output } Denormalizer::MethodOutput.create(attributes) else saved_output.method_output = method_output saved_output.save end end end end