forked from zerohistory/toystore
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partially implemented dirty checking
- Loading branch information
Showing
3 changed files
with
28 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
module Toy | ||
module Dirty | ||
|
||
extend ActiveSupport::Concern | ||
include ActiveModel::Dirty | ||
|
||
module InstanceMethods | ||
def attributes_changed!(attributes) | ||
attributes.each do |attr_name| | ||
attribute_will_change!(attr_name) | ||
end | ||
end | ||
|
||
def save | ||
super.tap { changed_attributes.clear } | ||
end | ||
|
||
def write_attribute(name, value) | ||
name = name.to_s | ||
unless attribute_changed?(name) | ||
old = read_attribute(name) | ||
changed_attributes[name] = old if old != value | ||
end | ||
super | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters