Class: Virtus::Dirty::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus/dirty/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Session

Returns a new instance of Session.



7
8
9
# File 'lib/virtus/dirty/session.rb', line 7

def initialize(subject)
  @subject = subject
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



4
5
6
# File 'lib/virtus/dirty/session.rb', line 4

def subject
  @subject
end

Instance Method Details

#dirty!(name, value) ⇒ Object

Sets an attribute as dirty

Parameters:

  • name (Symbol)

    the name of an attribute

  • value (Object)

    the value of an attribute



40
41
42
# File 'lib/virtus/dirty/session.rb', line 40

def dirty!(name, value)
  dirty_attributes[name] = value
end

#dirty?(name = nil) ⇒ TrueClass, FalseClass

Returns if an object is dirty or if an attribute with the given name is dirty.

Parameters:

  • name (Symbol) (defaults to: nil)

    the name of an attribute

Returns:

  • (TrueClass, FalseClass)


53
54
55
# File 'lib/virtus/dirty/session.rb', line 53

def dirty?(name = nil)
  name ? dirty_attributes.key?(name) : dirty_attributes.any?
end

#dirty_attributesHash

Returns dirty attributes of the subject

Returns:

  • (Hash)

    a hash of attributes indexed by attribute names



27
28
29
# File 'lib/virtus/dirty/session.rb', line 27

def dirty_attributes
  @_dirty_attributes ||= {}
end

#original_attributesHash

Returns original attributes of the subject

Returns:

  • (Hash)

    a hash of attributes indexed by attribute names



17
18
19
# File 'lib/virtus/dirty/session.rb', line 17

def original_attributes
  @_original_attributes ||= subject.attributes.dup
end