Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created March 20, 2010 07:53
Show Gist options
  • Save pathsny/338541 to your computer and use it in GitHub Desktop.
Save pathsny/338541 to your computer and use it in GitHub Desktop.
class Collection
def update!(attributes)
...
model = self.model
dirty_attributes = model.new(attributes).dirty_attributes
if dirty_attributes.empty?
true
elsif dirty_attributes.any? { |property, value| !property.valid?(value) }
false
else
unless _update(dirty_attributes)
...
end
end
class Resource
def _update
original_attributes = self.original_attributes
if original_attributes.empty?
true
elsif original_attributes.any? { |property, _value| !property.valid?(property.get!(self)) }
false
else
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment