Last active
December 11, 2015 04:18
-
-
Save tbaba/4543857 to your computer and use it in GitHub Desktop.
ActiveRecord::QueryMethods#all!
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
Gem::Specification.new do |gem| | |
gem.name = "all_or_nothing" | |
gem.version = '0.0.1' | |
gem.authors = ["Tatsuro Baba"] | |
gem.email = ["harakirisoul@gmail.com"] | |
gem.description = %q{TODO: Write a gem description} | |
gem.summary = %q{TODO: Write a gem summary} | |
gem.homepage = "https://gist.github.com/4543857" | |
gem.files = ['all_or_nothing.rb'] | |
gem.require_path = '.' | |
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
module ActiveRecord | |
module QueryMethods | |
def all_or_nothing! | |
relation = clone | |
result = relation.all | |
if result.blank? | |
raise ActiveRecord::RecordNotFound | |
else | |
result | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method returns ActiveRecord::RecordNotFound exception if result of this relation is empty.