From 56aef70e9ef47de0facc6f32f52693a80eea56bf Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Tue, 29 Aug 2023 09:18:36 +0200 Subject: [PATCH] Allow raw data access on ResourceObject When processing large JSON responses, the repeated instantiation of objects makes this processing extremely slow. Allowing raw data access allows much faster reading of responses. These changes allow users to skip convenience methods when all they need is the data itself. --- lib/excon/hypermedia/resource_object.rb | 2 ++ test/excon/resource_object_test.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/excon/hypermedia/resource_object.rb b/lib/excon/hypermedia/resource_object.rb index 2d7dda3..77971ad 100644 --- a/lib/excon/hypermedia/resource_object.rb +++ b/lib/excon/hypermedia/resource_object.rb @@ -13,6 +13,8 @@ module HyperMedia class ResourceObject RESERVED_PROPERTIES = %w[_links _embedded].freeze + attr_reader :data + def initialize(data) @data = data end diff --git a/test/excon/resource_object_test.rb b/test/excon/resource_object_test.rb index 4f01133..711cbbc 100644 --- a/test/excon/resource_object_test.rb +++ b/test/excon/resource_object_test.rb @@ -31,7 +31,7 @@ def resource end def test_resource - assert_equal data, resource.instance_variable_get(:@data) + assert_equal data, resource.data end def test_links