Module: ActiveRecord::TypedStore::Extension

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_record/typed_store/extension.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#changesObject



74
75
76
77
78
79
80
81
82
# File 'lib/active_record/typed_store/extension.rb', line 74

def changes
  changes = super
  self.class.store_accessors.each do |attr|
    if send("#{attr}_changed?")
      changes[attr] = [send("#{attr}_was"), send(attr)]
    end
  end
  changes
end

#clear_attribute_change(attr_name) ⇒ Object



84
85
86
87
# File 'lib/active_record/typed_store/extension.rb', line 84

def clear_attribute_change(attr_name)
  return if self.class.store_accessors.include?(normalize_attribute(attr_name))
  super
end

#normalize_attribute(attr) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/active_record/typed_store/extension.rb', line 115

def normalize_attribute(attr)
  case attr
  when Symbol
    attr
  else
    attr.to_s.to_sym
  end
end

#query_attribute(attr_name) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/active_record/typed_store/extension.rb', line 96

def query_attribute(attr_name)
  if self.class.store_accessors.include?(attr_name.to_sym)
    value = public_send(attr_name)

    case value
    when true        then true
    when false, nil  then false
    else
      if value.respond_to?(:zero?)
        !value.zero?
      else
        !value.blank?
      end
    end
  else
    super
  end
end

#read_attribute(attr_name) ⇒ Object



89
90
91
92
93
94
# File 'lib/active_record/typed_store/extension.rb', line 89

def read_attribute(attr_name)
  if self.class.store_accessors.include?(normalize_attribute(attr_name))
    return public_send(attr_name)
  end
  super
end