From 3fccd330baebb47dfbb69c81902708d311d8f30e Mon Sep 17 00:00:00 2001 From: Clay Date: Sun, 20 May 2012 12:35:50 -0400 Subject: [PATCH] refactor .methods and .respond_to? to use a single remote_model_methods array. --- lib/remote_model.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/remote_model.rb b/lib/remote_model.rb index 5301dfc..ff0c927 100644 --- a/lib/remote_model.rb +++ b/lib/remote_model.rb @@ -107,18 +107,26 @@ def update_attributes(params = {}) end end - def methods - methods = super - + def remote_model_methods + methods = [] [self.class.has_one, self.class.has_many, self.class.belongs_to].each {|fn_hash| methods += fn_hash.collect {|sym, klass| [sym, (sym.to_s + "=:").to_sym] }.flatten } + methods + RemoteModule::RemoteModel::HTTP_METHODS + end + + def methods + super + remote_model_methods + end - methods += RemoteModule::RemoteModel::HTTP_METHODS + def respond_to?(symbol, include_private = false) + if remote_model_methods.include? symbol + return true + end - methods + super end def method_missing(sym, *args, &block)