Module: AttrCsv::InstanceMethods
- Defined in:
- lib/attr-csv.rb
Instance Method Summary collapse
- #decode(attribute, csv_value) ⇒ Object
- #encode(attribute, array_value) ⇒ Object
-
#update_csved_attributes ⇒ Object
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.
Instance Method Details
#decode(attribute, csv_value) ⇒ Object
92 93 94 |
# File 'lib/attr-csv.rb', line 92 def decode(attribute, csv_value) self.class.decode(attribute, csv_value) end |
#encode(attribute, array_value) ⇒ Object
96 97 98 |
# File 'lib/attr-csv.rb', line 96 def encode(attribute, array_value) self.class.encode(attribute, array_value) end |
#update_csved_attributes ⇒ Object
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.
107 108 109 110 111 112 |
# 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 |