Method: ConfigScripts::Seeds::SeedType#write_value_for_attribute
- Defined in:
- lib/config_scripts/seeds/seed_type.rb
#write_value_for_attribute(item, attribute) ⇒ String
This method gets the value that we should write into the CSV file for an attribute.
If the value for that attribute is another model record, this will get its seed identifier from the seed set. Otherwise, it will just use the value.
If the attribute is a polymorphic foreign key, this will prefix the seed identifier with the class name.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/config_scripts/seeds/seed_type.rb', line 242 def write_value_for_attribute(item, attribute) if @dynamic_writers[attribute] value = @dynamic_writers[attribute].call(item) else value = item.send(attribute) end if value.is_a?(ActiveRecord::Base) identifier = self.seed_set.seed_identifier_for_record(value) if !self.associations[attribute] identifier = "#{value.class.name}::#{identifier}" end value = identifier elsif value.is_a?(TrueClass) value = '1' elsif value.is_a?(FalseClass) value = '0' end value end |