Module: ActiveRecord::TypedStore::Behavior

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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

#changesObject



34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



44
45
46
47
# 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) ⇒ Object



49
50
51
52
53
54
# 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