cardmagic / standard_failure

A rails plugin for handling standard failures in an app

This URL has Read+Write access

name age message
file README Loading commit data...
file Rakefile
file init.rb
directory lib/
directory test/
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