Skip to content

Commit

Permalink
@wip Dirty complete
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed May 10, 2020
1 parent f0ca455 commit 0641cd3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/dynamoid/dirty.rb
Expand Up @@ -84,7 +84,7 @@ def reload(*)
# Returns +true+ if any attribute have unsaved changes, +false+ otherwise.
#
# person.changed? # => false
# person.name = 'bob'
# person.name = 'Bob'
# person.changed? # => true
#
# @return [true|false]
Expand Down Expand Up @@ -118,10 +118,10 @@ def changes

# Returns a hash of attributes that were changed before the model was saved.
#
# person.name # => "bob"
# person.name = 'robert'
# person.name # => "Bob"
# person.name = 'Robert'
# person.save
# person.previous_changes # => {"name" => ["bob", "robert"]}
# person.previous_changes # => {"name" => ["Bob", "Robert"]}
#
# @return [ActiveSupport::HashWithIndifferentAccess]
def previous_changes
Expand All @@ -131,9 +131,9 @@ def previous_changes
# Returns a hash of the attributes with unsaved changes indicating their original
# values like <tt>attr => original value</tt>.
#
# person.name # => "bob"
# person.name = 'robert'
# person.changed_attributes # => {"name" => "bob"}
# person.name # => "Bob"
# person.name = 'Robert'
# person.changed_attributes # => {"name" => "Bob"}
#
# @return [ActiveSupport::HashWithIndifferentAccess]
def changed_attributes
Expand All @@ -150,6 +150,8 @@ def changed_attributes
# @api private
# @param attr [Symbol] attribute name
# @param options [Hash] conditions on +from+ and +to+ value (optional)
# @option options [Symbol] :from previous attribute value
# @option options [Symbol] :to current attribute value
def attribute_changed?(attr, options = {})
result = changes_include?(attr)
result &&= options[:to] == __send__(attr) if options.key?(:to)
Expand Down

0 comments on commit 0641cd3

Please sign in to comment.