-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0af1af0
commit ed667f5
Showing
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = | ||
errors: | ||
missingCallback: "Você deve passar um callback para %s." | ||
missingOption: "Você deve passar a opção '%s' para %s." | ||
notFound: "%s não encontrado." | ||
store: | ||
missingAttribute: "Faltando %s no %s para '%s'" | ||
asset: | ||
notFound: "Asset não encontrado: '%s'\n Paths procurados: [\n%s\n ]" |
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,47 @@ | ||
Tower.SupportRescuable = | ||
ClassMethods: | ||
rescueHandlers: -> | ||
@_rescueHandlers ||= [] | ||
|
||
rescueFrom: -> | ||
klasses = _.args(arguments) | ||
block = _.extractBlock(klasses) | ||
options = _.extractOptions(klasses) | ||
key = undefined | ||
|
||
unless options.hasOwnProperty("with") | ||
if block | ||
options.with = block | ||
else | ||
throw new ArgumentError("Need a handler. Supply an options hash that has a `with` key as the last argument.") | ||
|
||
for klass in klasses | ||
#key = if klass.isA?(Class) && klass <= Exception | ||
# klass.name | ||
if typeof klass == "string" | ||
key = klass | ||
else | ||
throw new ArgumentError("#{klass} is neither an Exception nor a String") | ||
|
||
@rescueHandlers().push [key, options.with] | ||
|
||
InstanceMethods: | ||
rescueWithHandler: (exception) -> | ||
if handler = @handlerForRescue(exception) | ||
if handler.length != 0 then handler.call(exception) else handler.call() | ||
true | ||
|
||
handlerForRescue: (exception) -> | ||
handlers = @constructor.rescueHandlers().reverse() | ||
rescuer = undefined | ||
|
||
for array in handlers | ||
[klassName, handler] = array | ||
|
||
klass = Tower.constant(klassName) | ||
# exception.isA?(klass) if klass | ||
rescuer = handler | ||
|
||
rescuer | ||
|
||
module.exports = Tower.SupportRescuable |