Class: Virtus::DirtyAttribute::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus/dirty_attribute/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_attribute/session.rb', line 7

def initialize(subject)
  @subject = subject
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/virtus/dirty_attribute/session.rb', line 5

def subject
  @subject
end

Instance Method Details

#attribute_clean!(name) ⇒ Object



23
24
25
26
# File 'lib/virtus/dirty_attribute/session.rb', line 23

def attribute_clean!(name)
  dirty_attributes.delete name
  original_attributes.delete name
end

#clean!Object



32
33
34
35
# File 'lib/virtus/dirty_attribute/session.rb', line 32

def clean!
  original_attributes.clear
  dirty_attributes.clear
end

#dirty!(name, value) ⇒ Object



19
20
21
# File 'lib/virtus/dirty_attribute/session.rb', line 19

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

#dirty?(name = nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/virtus/dirty_attribute/session.rb', line 28

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

#dirty_attributesObject



15
16
17
# File 'lib/virtus/dirty_attribute/session.rb', line 15

def dirty_attributes
  @_dirty_attributes ||= {}
end

#original_attributesObject



11
12
13
# File 'lib/virtus/dirty_attribute/session.rb', line 11

def original_attributes
  @_original_attributes ||= get_original_attributes(subject).dup
end