class ActiveRecord::Has::SparseAttributes::ColumnStorage
Attributes
updated_attributes[RW]
Public Instance Methods
after_save(*args)
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 54 def after_save(*args) clear_updated_sparse_attributes() end
before_update(*args)
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 50 def before_update(*args) merge_sparse_attributes() end
get(name)
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 26 def get(name) col = @config.column_name return nil if @record[col].nil? return @record[col][name.to_s] end
set(name, value)
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 32 def set(name, value) name = name.to_s col = @config.column_name @updated_attributes = {} if @updated_attributes.nil? if @record[col].nil? @record[col] = {} end a = @record[col] if value.nil? a.delete(name) else value = value.to_s if !@config.serialize_values a[name] = value end @updated_attributes[name] = true @record[col] = a end
Protected Instance Methods
clear_updated_sparse_attributes()
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 78 def clear_updated_sparse_attributes @updated_attributes = {} end
merge_sparse_attributes()
click to toggle source
# File lib/active_record/has/sparse_attributes/column_storage.rb, line 60 def merge_sparse_attributes() return if @updated_attributes.nil? col = @config.column_name obj = @config.model_class.select(col.to_s).find(@record.id) current = obj[col] if current.nil? or current.empty? return end @updated_attributes.each do |key, value| if @record[col].has_key?(key) current[key] = @record[col][key] else current.delete(key) end end @record[col] = current end