Skip to content

Commit

Permalink
merge dev to master
Browse files Browse the repository at this point in the history
  • Loading branch information
lancejpollard committed Aug 21, 2012
1 parent 0af1af0 commit ed667f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/tower-application/shared/locale/ptBr.coffee
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 ]"
47 changes: 47 additions & 0 deletions packages/tower-support/shared/rescuable.coffee
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

0 comments on commit ed667f5

Please sign in to comment.