Sha256: 1f8f1d1f706395ab2558381b4dc6d3881b1c07181a139bc807446db10f5dc39e
Contents?: true
Size: 695 Bytes
Versions: 1
Compression:
Stored size: 695 Bytes
Contents
module PersistedAttributes class Changes::CreateOrUpdate attr_reader :record, :value, :field_name, :field_type, :attribute def initialize(value, field_name, field_type, record) @value, @field_name, @field_type, @record = value, field_name, field_type, record @attribute = find_or_build_attribute end def save attribute.value = value record.public_send("#{field_name}_attribute=", attribute) end private def find_or_build_attribute record.dynamic_fields_attributes.find_or_initialize_by( name: field_name, type: PersistedAttributes::Attribute.attribute_class_for_attribute_type(field_type) ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
persisted_attributes-0.1.0 | lib/persisted_attributes/changes/create_or_update.rb |