module AttrCsv::InstanceMethods
Public Instance Methods
decode(attribute, csv_value)
click to toggle source
# File lib/attr-csv.rb, line 92 def decode(attribute, csv_value) self.class.decode(attribute, csv_value) end
encode(attribute, array_value)
click to toggle source
# File lib/attr-csv.rb, line 96 def encode(attribute, array_value) self.class.encode(attribute, array_value) end
update_csved_attributes()
click to toggle source
For ActiveRecord models, this method is called as a before_validation callback to ensure that the CSV values have been update to the ‘_csv’ columns appropriately. The user might have used an array modifier directly (e.g. << or push), which we wouldn’t see. So, to make sure the database gets updated appropriately, we do this.
# File lib/attr-csv.rb, line 107 def update_csved_attributes self.class.csved_attributes.each do | attribute | csv_attribute_name = [ attribute.to_s, CSV_ATTR_EXTENSION ].join.to_sym send("#{csv_attribute_name}=", encode(attribute, send(attribute))) end end