From 9909bb0ef777fd1e99555bd5bb030fd80f0bd0ca Mon Sep 17 00:00:00 2001 From: shalvah-gs Date: Thu, 7 Sep 2023 00:04:15 +0200 Subject: [PATCH 1/2] Add #to_h to models; make #inspect dump all attributes --- lib/calendly/models/model_utils.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/calendly/models/model_utils.rb b/lib/calendly/models/model_utils.rb index eeaa358..f9be78e 100644 --- a/lib/calendly/models/model_utils.rb +++ b/lib/calendly/models/model_utils.rb @@ -13,6 +13,7 @@ module ModelUtils # @param [Calendly::Client] the api client. def initialize(attrs = nil, client = nil) @client = client + @data = attrs || {} set_attributes attrs end @@ -47,15 +48,21 @@ def id # @since 0.0.1 def inspect att_info = [] - inspect_attributes.each do |att| + + # Print out all the attributes, showing the key ones (defined in inspect_attributes) first + (inspect_attributes + @data.keys).uniq.each do |att| next unless respond_to? att att_info << "#{att}=#{send(att).inspect}" end - att_info << '..' + "\#<#{self.class}:#{object_id} #{att_info.join(', ')}>" end + def to_h + @data + end + module ClassMethods def extract_uuid_match(str) return unless defined? self::UUID_RE From 30a74272b6b4ffd5d3b023bef526375c6e5a2113 Mon Sep 17 00:00:00 2001 From: shalvah-gs Date: Mon, 16 Oct 2023 12:45:51 +0200 Subject: [PATCH 2/2] Adjust parameter name --- lib/calendly/models/model_utils.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/calendly/models/model_utils.rb b/lib/calendly/models/model_utils.rb index f9be78e..0090dec 100644 --- a/lib/calendly/models/model_utils.rb +++ b/lib/calendly/models/model_utils.rb @@ -13,7 +13,7 @@ module ModelUtils # @param [Calendly::Client] the api client. def initialize(attrs = nil, client = nil) @client = client - @data = attrs || {} + @__data = attrs || {} set_attributes attrs end @@ -50,7 +50,7 @@ def inspect att_info = [] # Print out all the attributes, showing the key ones (defined in inspect_attributes) first - (inspect_attributes + @data.keys).uniq.each do |att| + (inspect_attributes + @__data.keys).uniq.each do |att| next unless respond_to? att att_info << "#{att}=#{send(att).inspect}" @@ -60,7 +60,7 @@ def inspect end def to_h - @data + @__data end module ClassMethods