From 945273924479d8b4195b514b3fd6e5556e2cee85 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 23 Oct 2013 12:18:18 -0700 Subject: [PATCH] Add addProxy() method to Adaptor class --- src/adaptor.coffee | 3 +++ test/src/specs/adaptor.spec.coffee | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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"