Permalink
Browse files

merge dev to master

  • Loading branch information...
1 parent 0af1af0 commit ed667f5b9ec210c841c6aac4ca0ba3871ec0e709 @lancejpollard lancejpollard committed Aug 21, 2012
@@ -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 ]"
@@ -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.