Permalink
Browse files

allow before and after to be defined prior to defining the default

  • Loading branch information...
1 parent 627967a commit 47e4cf2c5f4fbf050241a8577a638bf68de8c5b3 @raganwald committed May 7, 2012
Showing with 27 additions and 7 deletions.
  1. +5 −3 lib/YouAreDaChef.coffee
  2. +9 −3 lib/YouAreDaChef.js
  3. +1 −1 package.json
  4. +12 −0 spec/YouAreDaChef.spec.coffee
View
8 lib/YouAreDaChef.coffee
@@ -72,13 +72,15 @@ _.defaults this,
# this patches the original method to call advices and pass match data
unless clazz.prototype.hasOwnProperty(name) and daemonology.default?
if _.include(_.keys(clazz.prototype), name)
- daemonology.default = ['!', clazz.prototype[name]]
+ daemonology.default = ['', clazz.prototype[name]]
else if clazz.__super__?
- daemonology.default = ['!', (args...) ->
+ daemonology.default = ['', (args...) ->
clazz.__super__[name].apply(this, args)
]
else
- throw 'No method or superclass given ' + name
+ daemonology.default = ['!', (args...) ->
+ throw 'No method or superclass defined for ' + name
+ ]
clazz.prototype[name] = (args...) ->
if clazz.prototype["guard_#{name}_daemon"].apply(this, args)
clazz.prototype["before_#{name}_daemon"].apply(this, args)
View
12 lib/YouAreDaChef.js
@@ -96,17 +96,23 @@
}
if (!(clazz.prototype.hasOwnProperty(name) && (daemonology["default"] != null))) {
if (_.include(_.keys(clazz.prototype), name)) {
- daemonology["default"] = ['!', clazz.prototype[name]];
+ daemonology["default"] = ['', clazz.prototype[name]];
} else if (clazz.__super__ != null) {
daemonology["default"] = [
- '!', function() {
+ '', function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return clazz.__super__[name].apply(this, args);
}
];
} else {
- throw 'No method or superclass given ' + name;
+ daemonology["default"] = [
+ '!', function() {
+ var args;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ throw 'No method or superclass defined for ' + name;
+ }
+ ];
}
clazz.prototype[name] = function() {
var args, _ref3;
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Reg Braithwaite <raganwald@gmail.com> (http://braythwayt.com)",
"name": "YouAreDaChef",
"description": "Coffeescript/Javascript method combinations",
- "version": "1.0.3",
+ "version": "1.0.4",
"homepage": "https://github.com/raganwald/YouAreDaChef",
"repository": {
"type": "git",
View
12 spec/YouAreDaChef.spec.coffee
@@ -197,6 +197,18 @@ describe 'YouAreDaChef', ->
named_advice: (meters) -> "#{@name} sauntered #{meters}m."
expect(abe.move(5)).toBe("Rumplestiltskin sauntered 5m.")
+
+ it 'should allow defeault definition of a new method without a superclass', ->
+
+ class Mumps
+
+ YouAreDaChef(Mumps)
+ .after
+ foo: ->
+ .default
+ foo: ->
+
+ expect(new Mumps().foo()).toBeFalsy()
class Nag extends Horse
class Arabian extends Horse

0 comments on commit 47e4cf2

Please sign in to comment.