Method: Naf::ApplicationScheduleAffinityTab#pickle

Defined in:
app/models/naf/application_schedule_affinity_tab.rb

#pickle(pickler, associations = nil, ignored_attributes = [:created_at, :updated_at]) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/naf/application_schedule_affinity_tab.rb', line 56

def pickle(pickler, associations = nil, ignored_attributes = [:created_at, :updated_at])
  instance_attributes = attributes.symbolize_keys
  ignored_attributes.each do |ignored_attribute|
    instance_attributes.delete(ignored_attribute.to_sym)
  end

  unless associations
    associations = {}
    instance_attributes.keys.select{|key| key.to_s =~ /_id$/}.each do |key|
      association_name = key.to_s[0..-4].to_sym
      association = association(association_name) rescue nil
      if association
        associations[key] = association.options[:class_name].constantize.name
      end
    end
  end

  return Hash[instance_attributes.map { |key, value|
                if associations[key] == 'Naf::Affinity'
                  [key, { association_model_name: associations[key],
                          association_classification_value: affinity.affinity_classification_id,
                          association_affinity_value: affinity.affinity_name }]
                elsif associations[key] == 'Naf::ApplicationSchedule'
                  [key, { association_model_name: associations[key], association_value: value }]
                else
                  [key,value]
                end
              } ]
end