Skip to content

Commit

Permalink
Merge pull request #12 from avvo/custom_function_support
Browse files Browse the repository at this point in the history
adding result parsing and Resourcifying to method_missing calls
  • Loading branch information
Brandon Sislow committed Jul 24, 2015
2 parents 1fbf9b7 + 2600413 commit 56e6faf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/json_api_resource/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ def catch_errors
def self.method_missing(method, *args, &block)
if match = method.to_s.match(/^(.*)=$/)
self.client_klass.send(match[1], args.first)

elsif self.client_klass.respond_to?(method.to_sym)
self.client_klass.send(method, *args)
results = self.client_klass.send(method, *args)

if results.is_a? JsonApiClient::ResultSet
results.map! do |result|
self.new(:client => result)
end
end
results
else
super
end

rescue JsonApiClient::Errors::ServerError => e
pretty_error e
end
end
end

0 comments on commit 56e6faf

Please sign in to comment.