Class: ActiveRecord::Has::SparseAttributes::ColumnStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/active_record/has/sparse_attributes/column_storage.rb

Instance Attribute Summary collapse

Attributes inherited from Storage

#config, #record

Instance Method Summary collapse

Methods inherited from Storage

#before_save, #initialize

Constructor Details

This class inherits a constructor from ActiveRecord::Has::SparseAttributes::Storage

Instance Attribute Details

#updated_attributesObject

Returns the value of attribute updated_attributes.



24
25
26
# File 'lib/active_record/has/sparse_attributes/column_storage.rb', line 24

def updated_attributes
  @updated_attributes
end

Instance Method Details

#after_save(*args) ⇒ Object



54
55
56
# File 'lib/active_record/has/sparse_attributes/column_storage.rb', line 54

def after_save(*args)
  clear_updated_sparse_attributes()
end

#before_update(*args) ⇒ Object



50
51
52
# File 'lib/active_record/has/sparse_attributes/column_storage.rb', line 50

def before_update(*args)
  merge_sparse_attributes()
end

#get(name) ⇒ Object



26
27
28
29
30
# 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) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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