Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API change: save_resource and resource_saved? deprecated
ActiveRecord::Base now has a saved? and attempted_save? method, which makes response_for much easier to write, and leaves less artefacts in the controller instance. So save_resource, and resource_saved? are now deprecated, just use resource.save, and resource.saved? instead. See response_for_resources_controller if you're into response_for.
- Loading branch information
Showing
21 changed files
with
195 additions
and
43 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
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
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
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,3 +1,5 @@ | ||
require 'ardes/resources_controller' | ||
require 'ardes/active_record/saved' | ||
ActiveRecord::Base.send :include, Ardes::ActiveRecord::Saved | ||
|
||
ActionController::Base.extend Ardes::ResourcesController | ||
require 'ardes/resources_controller' | ||
ActionController::Base.extend Ardes::ResourcesController |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Ardes#:nodoc: | ||
module ActiveRecord#:nodoc: | ||
# Small mixin which lets you find the result of the last save on an active record | ||
# | ||
# Example usage: | ||
# | ||
# foo = Foo.new | ||
# | ||
# foo.attempted_save? # => false | ||
# foo.saved? # => nil | ||
# | ||
# foo.save # => true | ||
# foo.attempted_save? # => true | ||
# foo.saved? # => true | ||
# | ||
# foo.update_attributes(:invalid => true) # => false | ||
# foo.attempted_save? # => true | ||
# foo.saved? # => false | ||
# | ||
# foo.reload | ||
# foo.attempted_save? # => false | ||
# foo.saved? # => false | ||
module Saved | ||
def self.included(base) | ||
base.class_eval do | ||
def save_with_saved(*args) | ||
@_saved = save_without_saved(*args) | ||
end | ||
alias_method_chain :save, :saved | ||
|
||
def reload_with_saved(*args) | ||
@_saved = nil | ||
reload_without_saved(*args) | ||
end | ||
alias_method_chain :reload, :saved | ||
|
||
# returns: | ||
# nil - if the record has had no save attempt | ||
# true - if the record was saved successfuly | ||
# false - if the record was saved unsuccesfuly | ||
def saved? | ||
@_saved | ||
end | ||
|
||
# returns: | ||
# true - if the record has had a save attempt | ||
# false - if the record has not had a save attempt | ||
# (this is simply a predicate method for checking saved?.nil?) | ||
def attempted_save? | ||
!@_saved.nil? | ||
end | ||
end | ||
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
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
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
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
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
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
Oops, something went wrong.