Module: Virtus::DirtyAttribute

Defined in:
lib/virtus/dirty_attribute.rb,
lib/virtus/dirty_attribute/session.rb

Overview

Dirty Tracking

Dirty Tracking is an optional module that you include only if you need it.

Defined Under Namespace

Modules: ClassMethods, InitiallyClean Classes: Session

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



59
60
61
# File 'lib/virtus/dirty_attribute.rb', line 59

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attribute_clean!(name) ⇒ Object



94
95
96
# File 'lib/virtus/dirty_attribute.rb', line 94

def attribute_clean!(name)
  dirty_session.attribute_clean!(name)
end

#attribute_dirty!(name, value) ⇒ Object



90
91
92
# File 'lib/virtus/dirty_attribute.rb', line 90

def attribute_dirty!(name, value)
  dirty_session.dirty!(name, value)
end

#attribute_dirty?(name, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/virtus/dirty_attribute.rb', line 71

def attribute_dirty?(name, options = {})
  result = dirty_session.dirty?(name)
  result &&= options[:to] == dirty_attributes[name] if options.key?(:to)
  result &&= options[:from] == original_attributes[name] if options.key?(:from)
  result
end

#clean!Object



78
79
80
# File 'lib/virtus/dirty_attribute.rb', line 78

def clean!
  dirty_session.clean!
end

#clean?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/virtus/dirty_attribute.rb', line 67

def clean?
  !dirty?
end

#dirty?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/virtus/dirty_attribute.rb', line 63

def dirty?
  dirty_session.dirty?
end

#dirty_attributesObject



82
83
84
# File 'lib/virtus/dirty_attribute.rb', line 82

def dirty_attributes
  dirty_session.dirty_attributes
end

#original_attributesObject



86
87
88
# File 'lib/virtus/dirty_attribute.rb', line 86

def original_attributes
  dirty_session.original_attributes
end