Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/json_api_client/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module Helpers
autoload :DynamicAttributes, 'json_api_client/helpers/dynamic_attributes'
autoload :URI, 'json_api_client/helpers/uri'
autoload :Associatable, 'json_api_client/helpers/associatable'
autoload :Debug, 'json_api_client/helpers/debug'
end
end
17 changes: 17 additions & 0 deletions lib/json_api_client/helpers/debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module JsonApiClient
module Helpers
module Debug
def self.included(_base)
$_resource_attribute_calls = {}
end

def track_resource_attribute_calls
yield
ensure
puts '----------------------------------------------------------'
pp $_resource_attribute_calls
puts '----------------------------------------------------------'
end
end
end
end
6 changes: 6 additions & 0 deletions lib/json_api_client/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,12 @@ def relation_objects_for(name, relationship_definition)
end

def method_missing(method, *args)
if defined?($_resource_attribute_calls) && !method.to_s.ends_with?('=')
$_resource_attribute_calls[self.class.to_s] ||= {}
$_resource_attribute_calls[self.class.to_s][method] ||= 0
$_resource_attribute_calls[self.class.to_s][method] += 1
end

relationship_definition = relationship_definition_for(method)

return super unless relationship_definition
Expand Down