Skip to content

Commit

Permalink
refactor .methods and .respond_to? to use a single remote_model_metho…
Browse files Browse the repository at this point in the history
…ds array.
  • Loading branch information
clayallsopp committed May 20, 2012
1 parent 12cfe4a commit 3fccd33
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/remote_model.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 3fccd33

Please sign in to comment.