From cd574d77e1e48bf79b72e4312c8091d35aad97ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= Date: Tue, 4 Jan 2022 16:57:34 -0600 Subject: [PATCH 1/4] Use SimpleDelegator instead DelegateClass to support ruby 3 --- .gitignore | 2 ++ Gemfile.lock | 62 ----------------------------------------- lib/dolly/collection.rb | 2 +- 3 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index f049bb8..67a41ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.rbc /tmp/ /test/tmp/ +Gemfile.lock +.ruby-version diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 351aef3..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,62 +0,0 @@ -PATH - remote: . - specs: - dolly (3.1.2) - curb (= 0.9.8) - oj - -GEM - remote: https://rubygems.org/ - specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - crack (0.4.3) - safe_yaml (~> 1.0.0) - curb (0.9.8) - hashdiff (1.0.1) - metaclass (0.0.4) - mocha (1.9.0) - metaclass (~> 0.0.1) - oj (3.13.9) - power_assert (1.1.4) - public_suffix (4.0.6) - rake (13.0.3) - rexml (3.2.5) - rr (1.2.1) - safe_yaml (1.0.5) - test-unit (3.3.3) - power_assert - test-unit-context (0.5.1) - test-unit (>= 2.4.0) - test-unit-full (0.0.5) - test-unit - test-unit-context - test-unit-notify - test-unit-rr - test-unit-runner-tap - test-unit-notify (1.0.4) - test-unit (>= 2.4.9) - test-unit-rr (1.0.5) - rr (>= 1.1.1) - test-unit (>= 2.5.2) - test-unit-runner-tap (1.1.2) - test-unit - webmock (3.6.0) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - -PLATFORMS - ruby - -DEPENDENCIES - bundler (~> 2.0) - dolly! - mocha - rake (~> 13.0) - rexml - test-unit-full - webmock - -BUNDLED WITH - 2.2.16 diff --git a/lib/dolly/collection.rb b/lib/dolly/collection.rb index 10fb678..fdedcc0 100644 --- a/lib/dolly/collection.rb +++ b/lib/dolly/collection.rb @@ -1,7 +1,7 @@ require 'delegate' module Dolly - class Collection < DelegateClass(Array) + class Collection < SimpleDelegator attr_reader :options def initialize(rows: [], options: {}) From 0f5406914664b812d1c190ef75f5eb875a63a11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= Date: Wed, 5 Jan 2022 12:27:13 -0600 Subject: [PATCH 2/4] Fix typo in from json method --- lib/dolly/document_creation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dolly/document_creation.rb b/lib/dolly/document_creation.rb index fd8455e..7efa37c 100644 --- a/lib/dolly/document_creation.rb +++ b/lib/dolly/document_creation.rb @@ -16,7 +16,7 @@ def from_doc(doc) def from_json(json) raw_data = Oj.load(json, symbol_keys: true) - data = rails? ? data.with_indifferent_access : raw_data + data = rails? ? raw_data.with_indifferent_access : raw_data from_doc(data) end From 7fdfd0baaab2298f7aaaaa9d7e995a3e891d0481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= Date: Wed, 5 Jan 2022 12:45:13 -0600 Subject: [PATCH 3/4] Fix valid_property? method to check against symbols --- lib/dolly/document_state.rb | 1 - lib/dolly/property_manager.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/dolly/document_state.rb b/lib/dolly/document_state.rb index 3bb1ca2..a3e7fb9 100644 --- a/lib/dolly/document_state.rb +++ b/lib/dolly/document_state.rb @@ -41,7 +41,6 @@ def destroy is_hard = true def reload reloaded_doc = self.class.find(id).send(:doc) attributes = property_clean_doc(reloaded_doc) - attributes.each(&update_attribute) end diff --git a/lib/dolly/property_manager.rb b/lib/dolly/property_manager.rb index 5cd0f57..06e6084 100644 --- a/lib/dolly/property_manager.rb +++ b/lib/dolly/property_manager.rb @@ -25,7 +25,7 @@ def write_attribute(key, value) end def valid_property?(name) - properties.include?(name) + properties.include?(name.to_sym) end def update_doc(key, value) From 14c545e6593a00c9334c6b11a49f429624a20edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= Date: Wed, 5 Jan 2022 13:11:43 -0600 Subject: [PATCH 4/4] Improve property set [] method --- lib/dolly/property_set.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/dolly/property_set.rb b/lib/dolly/property_set.rb index 28b06d2..49a0d74 100644 --- a/lib/dolly/property_set.rb +++ b/lib/dolly/property_set.rb @@ -10,8 +10,7 @@ def <<(property) end def [](key) - return detect {|property| property.key == key } if key.is_a?(Symbol) - super + detect {|property| property.key == key.to_sym } end private