Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 47e4cf2c5f4fbf050241a8577a638bf68de8c5b3 1 parent 627967a
Reg Braithwaite authored May 06, 2012
8  lib/YouAreDaChef.coffee
@@ -72,13 +72,15 @@ _.defaults this,
72 72
           # this patches the original method to call advices and pass match data
73 73
           unless clazz.prototype.hasOwnProperty(name) and daemonology.default?
74 74
             if _.include(_.keys(clazz.prototype), name)
75  
-              daemonology.default = ['!', clazz.prototype[name]]
  75
+              daemonology.default = ['', clazz.prototype[name]]
76 76
             else if clazz.__super__?
77  
-              daemonology.default = ['!', (args...) ->
  77
+              daemonology.default = ['', (args...) ->
78 78
                 clazz.__super__[name].apply(this, args)
79 79
               ]
80 80
             else
81  
-              throw 'No method or superclass given ' + name
  81
+              daemonology.default = ['!', (args...) ->
  82
+                throw 'No method or superclass defined for ' + name
  83
+              ]
82 84
             clazz.prototype[name] = (args...) ->
83 85
               if clazz.prototype["guard_#{name}_daemon"].apply(this, args)
84 86
                 clazz.prototype["before_#{name}_daemon"].apply(this, args)
12  lib/YouAreDaChef.js
@@ -96,17 +96,23 @@
96 96
             }
97 97
             if (!(clazz.prototype.hasOwnProperty(name) && (daemonology["default"] != null))) {
98 98
               if (_.include(_.keys(clazz.prototype), name)) {
99  
-                daemonology["default"] = ['!', clazz.prototype[name]];
  99
+                daemonology["default"] = ['', clazz.prototype[name]];
100 100
               } else if (clazz.__super__ != null) {
101 101
                 daemonology["default"] = [
102  
-                  '!', function() {
  102
+                  '', function() {
103 103
                     var args;
104 104
                     args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
105 105
                     return clazz.__super__[name].apply(this, args);
106 106
                   }
107 107
                 ];
108 108
               } else {
109  
-                throw 'No method or superclass given ' + name;
  109
+                daemonology["default"] = [
  110
+                  '!', function() {
  111
+                    var args;
  112
+                    args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  113
+                    throw 'No method or superclass defined for ' + name;
  114
+                  }
  115
+                ];
110 116
               }
111 117
               clazz.prototype[name] = function() {
112 118
                 var args, _ref3;
2  package.json
@@ -2,7 +2,7 @@
2 2
   "author": "Reg Braithwaite <raganwald@gmail.com> (http://braythwayt.com)",
3 3
   "name": "YouAreDaChef",
4 4
   "description": "Coffeescript/Javascript method combinations",
5  
-  "version": "1.0.3",
  5
+  "version": "1.0.4",
6 6
   "homepage": "https://github.com/raganwald/YouAreDaChef",
7 7
   "repository": {
8 8
     "type": "git",
12  spec/YouAreDaChef.spec.coffee
@@ -197,6 +197,18 @@ describe 'YouAreDaChef', ->
197 197
         named_advice: (meters) -> "#{@name} sauntered #{meters}m."
198 198
 
199 199
     expect(abe.move(5)).toBe("Rumplestiltskin sauntered 5m.")
  200
+    
  201
+  it 'should allow defeault definition of a new method without a superclass', ->
  202
+    
  203
+    class Mumps
  204
+      
  205
+    YouAreDaChef(Mumps)
  206
+      .after
  207
+        foo: ->
  208
+      .default
  209
+        foo: ->
  210
+          
  211
+    expect(new Mumps().foo()).toBeFalsy()
200 212
 
201 213
 class Nag extends Horse
202 214
 class Arabian extends Horse

0 notes on commit 47e4cf2

Please sign in to comment.
Something went wrong with that request. Please try again.