module ActiveRecord::TypedStore::Behavior

Public Instance Methods

attribute?(attr_name) click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 56
def attribute?(attr_name)
  if self.class.store_accessors.include?(attr_name.to_s)
    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
changes() click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 34
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) click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 44
def clear_attribute_change(attr_name)
  return if self.class.store_accessors.include?(attr_name.to_s)
  super
end
read_attribute(attr_name) click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 49
def read_attribute(attr_name)
  if self.class.store_accessors.include?(attr_name.to_s)
    return public_send(attr_name)
  end
  super
end

Private Instance Methods

attribute_names_for_partial_inserts() click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 77
def attribute_names_for_partial_inserts
  # Contrary to all vanilla Rails types, typedstore attribute have an inherent default
  # value that doesn't match the database column default.
  # As such we need to insert them on partial inserts even if they weren't changed.
  super | self.class.typed_stores.keys.map(&:to_s)
end
attribute_names_for_partial_updates() click to toggle source
Calls superclass method
# File lib/active_record/typed_store/behavior.rb, line 84
def attribute_names_for_partial_updates
  # On partial updates we shouldn't need to force stores to be persisted. However since
  # we weren't persisting them for a while on insertion, we now need to gracefully deal
  # with existing records that may have been persisted with a `NULL` store
  # We use `blank?` as an heuristic to detect these.
  super | self.class.typed_stores.keys.map(&:to_s).select do |store|
    @attributes.key?(store) && @attributes[store].value_before_type_cast.blank?
  end
end