From cc16f6adb8eb92f0f9e41c9d579cea3f60db0e51 Mon Sep 17 00:00:00 2001 From: ErickFabian Date: Fri, 12 Nov 2021 12:32:57 -0600 Subject: [PATCH] Fix issue with hashes not being indifferent access if available on document property build --- lib/dolly/framework_helper.rb | 2 +- lib/dolly/property.rb | 4 ++-- lib/dolly/property_set.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/dolly/framework_helper.rb b/lib/dolly/framework_helper.rb index 3e18232..599c04d 100644 --- a/lib/dolly/framework_helper.rb +++ b/lib/dolly/framework_helper.rb @@ -1,7 +1,7 @@ module Dolly module FrameworkHelper def rails? - defined?(ActiveSupport::HashWithIndifferentAccess) + !!defined?(ActiveSupport::HashWithIndifferentAccess) end end end diff --git a/lib/dolly/property.rb b/lib/dolly/property.rb index 36ffb1b..26c91b4 100644 --- a/lib/dolly/property.rb +++ b/lib/dolly/property.rb @@ -21,7 +21,7 @@ def cast_value(value) end def custom_class(value) - value = value.is_a?(Hash) ? value.symbolize_keys : value + value = value.is_a?(Hash) ? hash_with_indifferent_access_value(value) : value self_klass.new(value) end @@ -34,7 +34,7 @@ def string_value(value) end def hash_value(value) - value.to_h + hash_with_indifferent_access_value(value) end def hash_with_indifferent_access_value(value) diff --git a/lib/dolly/property_set.rb b/lib/dolly/property_set.rb index 28b06d2..91b729f 100644 --- a/lib/dolly/property_set.rb +++ b/lib/dolly/property_set.rb @@ -1,7 +1,7 @@ module Dolly class PropertySet < Set - def include? key - keys.include?(key) + def include?(key) + keys.include?(key.to_sym) end def <<(property) @@ -11,7 +11,7 @@ def <<(property) def [](key) return detect {|property| property.key == key } if key.is_a?(Symbol) - super + detect {|property| property.key.to_s == key } end private