diff --git a/src/adaptor.coffee b/src/adaptor.coffee index 5e5545c..537bcee 100644 --- a/src/adaptor.coffee +++ b/src/adaptor.coffee @@ -11,3 +11,6 @@ module.exports = class Adaptor constructor: (opts) -> @name = opts.name + + addProxy: (object, method) -> + this[method] = (args...) -> object[method](args...) diff --git a/test/src/specs/adaptor.spec.coffee b/test/src/specs/adaptor.spec.coffee index 81b4309..f32eb81 100644 --- a/test/src/specs/adaptor.spec.coffee +++ b/test/src/specs/adaptor.spec.coffee @@ -11,3 +11,15 @@ describe "Adaptor", -> it "should be able to connect" it "should be able to disconnect" + + it 'can alias methods with addProxy()', -> + proxyObject = { toString: -> "[object ProxyObject]" } + adaptor.addProxy(proxyObject, 'toString') + assert typeof adaptor.toString is 'function' + adaptor.toString().should.be.equal "[object ProxyObject]" + + it 'can alias methods with arguments with addProxy()', -> + proxyObject = { returnString: (string) -> string } + adaptor.addProxy(proxyObject, 'returnString') + assert typeof adaptor.returnString is 'function' + adaptor.returnString("testString").should.be.equal "testString"