cardmagic / standard_failure
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
README
Standard Failure
==============
Standard failure reduces the if/else logic that litters controllers.
error!(:artist_not_found, :retry => :still_not_found) { @artist.nil? || @artist.deleted? }
error!(:album_not_found, :retry => :still_not_found) { @album.nil? || @album.deleted? }
error(:incorrect_albums_artist_name, :unless => [:artist_not_found, :album_not_found]) { @album.artist.name !=
@artist.name }
The code above used to look like this:
if @artist.nil?
@artist_not_found = true
artist_not_found
if @artist.nil?
still_not_found
raise "error"
end
end
if @album.nil? || @album.deleted?
@album_not_found = true
album_not_found
if @album.nil? || @album.deleted?
still_not_found
raise "error"
end
end
unless @artist_not_found || @album_not_found
if @album.artist.name != @artist.name
incorrect_albums_artist_name
end
end
Copyright (c) 2008 Lucas Carlson, released under the MIT license
