Module: Virtus::Dirty

Defined in:
lib/virtus/dirty.rb,
lib/virtus/dirty/session.rb,
lib/virtus/dirty/version.rb

Overview

Dirty Tracking

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

Defined Under Namespace

Modules: Attribute Classes: Session

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extends a class with Dirty::Attribute module

Parameters:

  • base (Class)


14
15
16
# File 'lib/virtus/dirty.rb', line 14

def self.included(base)
  base.extend(Dirty::Attribute)
end

Instance Method Details

#attribute_dirty!(name, value) ⇒ Object

Explicitly sets an attribute as dirty.

Parameters:

  • name (Symbol)

    the name of an attribute

  • value (Object)

    a value of an attribute



47
48
49
# File 'lib/virtus/dirty.rb', line 47

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

#attribute_dirty?(name) ⇒ TrueClass, FalseClass

Returns if an attribute with the given name is dirty.

Parameters:

  • name (Symbol)

Returns:

  • (TrueClass, FalseClass)


34
35
36
# File 'lib/virtus/dirty.rb', line 34

def attribute_dirty?(name)
  dirty_session.dirty?(name)
end

#dirty?TrueClass, FalseClass

Returns if an object is dirty

Returns:

  • (TrueClass, FalseClass)


23
24
25
# File 'lib/virtus/dirty.rb', line 23

def dirty?
  dirty_session.dirty?
end

#dirty_attributesHash

Returns all dirty attributes

Returns:

  • (Hash)

    a hash indexed with attribute names



57
58
59
# File 'lib/virtus/dirty.rb', line 57

def dirty_attributes
  dirty_session.dirty_attributes
end

#dirty_sessionVirtus::Dirty::Session

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current dirty tracking session



76
77
78
# File 'lib/virtus/dirty.rb', line 76

def dirty_session
  @_dirty_session ||= Session.new(self)
end

#original_attributesHash

Returns original attributes

Returns:

  • (Hash)

    a hash indexed with attribute names



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

def original_attributes
  dirty_session.original_attributes
end