Module: PropertySets::ActiveRecordExtension::InstanceMethods

Defined in:
lib/property_sets/active_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#update(attributes) ⇒ Object Also known as: update_attributes



191
192
193
194
# File 'lib/property_sets/active_record_extension.rb', line 191

def update(attributes)
  update_property_set_attributes(attributes)
  super
end

#update!(attributes) ⇒ Object Also known as: update_attributes!



197
198
199
200
# File 'lib/property_sets/active_record_extension.rb', line 197

def update!(attributes)
  update_property_set_attributes(attributes)
  super
end

#update_columns(attributes) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/property_sets/active_record_extension.rb', line 213

def update_columns(attributes)
  if delegated_property_sets?
    attributes = attributes.reject{|k,_| self.class.delegated_property_set_attributes.include?(k.to_s) }
  end

  super attributes
end

#update_property_set_attributes(attributes) ⇒ Object



203
204
205
206
207
208
209
210
211
# File 'lib/property_sets/active_record_extension.rb', line 203

def update_property_set_attributes(attributes)
  if attributes && self.class.property_set_index.any?
    self.class.property_set_index.each do |property_set|
      if property_set_hash = attributes.delete(property_set)
        send(property_set).set(property_set_hash, true)
      end
    end
  end
end