diff --git a/lib/json_api_client/helpers.rb b/lib/json_api_client/helpers.rb index 6f6f71a..e8b0db4 100644 --- a/lib/json_api_client/helpers.rb +++ b/lib/json_api_client/helpers.rb @@ -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 diff --git a/lib/json_api_client/helpers/debug.rb b/lib/json_api_client/helpers/debug.rb new file mode 100644 index 0000000..7c9f004 --- /dev/null +++ b/lib/json_api_client/helpers/debug.rb @@ -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 diff --git a/lib/json_api_client/resource.rb b/lib/json_api_client/resource.rb index b0b0110..74ed4d3 100644 --- a/lib/json_api_client/resource.rb +++ b/lib/json_api_client/resource.rb @@ -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