Class: Virtus::Dirty::Session
- Inherits:
-
Object
- Object
- Virtus::Dirty::Session
- Defined in:
- lib/virtus/dirty/session.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
-
#dirty!(name, value) ⇒ Object
Sets an attribute as dirty.
-
#dirty?(name = nil) ⇒ TrueClass, FalseClass
Returns if an object is dirty or if an attribute with the given name is dirty.
-
#dirty_attributes ⇒ Hash
Returns dirty attributes of the subject.
-
#initialize(subject) ⇒ Session
constructor
A new instance of Session.
-
#original_attributes ⇒ Hash
Returns original attributes of the subject.
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
#subject ⇒ Object (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
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.
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_attributes ⇒ Hash
Returns dirty attributes of the subject
27 28 29 |
# File 'lib/virtus/dirty/session.rb', line 27 def dirty_attributes @_dirty_attributes ||= {} end |
#original_attributes ⇒ Hash
Returns original attributes of the subject
17 18 19 |
# File 'lib/virtus/dirty/session.rb', line 17 def original_attributes @_original_attributes ||= subject.attributes.dup end |