Skip to content

Commit

Permalink
ActiveModel::Dirty is now included in Cramp::Model::Base. When settin…
Browse files Browse the repository at this point in the history
…gs attributes, they are only changed if their are different from the existing ones.
  • Loading branch information
Rasmus Rønn Nielsen authored and Rasmus Rønn Nielsen committed Mar 25, 2010
1 parent 8f6a310 commit 5d1042a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/cramp/model/attribute_methods.rb
Expand Up @@ -42,7 +42,10 @@ def write_attribute(name, value)
if ma = self.class.model_attributes[name.to_sym]
value = ma.check_value!(value)
end
@attributes[name] = value
if(@attributes[name] != value)
send "#{name}_will_change!".to_sym
@attributes[name] = value
end
end

def read_attribute(name)
Expand Down
6 changes: 6 additions & 0 deletions lib/cramp/model/base.rb
Expand Up @@ -5,6 +5,7 @@ class Base
extend Finders
include AttributeMethods
include ActiveModel::Validations
include ActiveModel::Dirty
include Callbacks

class << self
Expand Down Expand Up @@ -82,6 +83,11 @@ def update_record(callback = nil, &block)
end

def after_save(status)
if status.success?
previously_changed_attributes = changes
changed_attributes.clear
end

after_save_callbacks status
end

Expand Down

0 comments on commit 5d1042a

Please sign in to comment.