summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordblock <dblock@dblock.org>2021-11-07 22:21:45 -0500
committerdblock <dblock@dblock.org>2021-11-07 22:21:45 -0500
commit25a3ff6e0498234d25de6a02bdbd3e508ade5898 (patch)
tree3ae1add7a8731daf46264b7a78cea9ac8b3278d0 /lib
parent796f9446fe3313685fe1a5c74052e1e942d170a2 (diff)
parent98df995e2f0433d3d1abe46efd732bc8e20e31cc (diff)
downloadhashie-25a3ff6e0498234d25de6a02bdbd3e508ade5898.tar.gz
Merge branch 'dash-nil-keys' of https://github.com/michaelherold/hashie into michaelherold-dash-nil-keys
Diffstat (limited to 'lib')
-rw-r--r--lib/hashie/dash.rb7
-rw-r--r--lib/hashie/extensions/dash/indifferent_access.rb9
-rw-r--r--lib/hashie/extensions/indifferent_access.rb7
3 files changed, 22 insertions, 1 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb
index 785d94d..cfb151e 100644
--- a/lib/hashie/dash.rb
+++ b/lib/hashie/dash.rb
@@ -156,6 +156,13 @@ module Hashie
self
end
+ def to_h
+ defaults = ::Hash[self.class.properties.map { |prop| [prop, self.class.defaults[prop]] }]
+
+ defaults.merge(self)
+ end
+ alias to_hash to_h
+
def update_attributes!(attributes)
update_attributes(attributes)
diff --git a/lib/hashie/extensions/dash/indifferent_access.rb b/lib/hashie/extensions/dash/indifferent_access.rb
index 204cae6..50d4f93 100644
--- a/lib/hashie/extensions/dash/indifferent_access.rb
+++ b/lib/hashie/extensions/dash/indifferent_access.rb
@@ -19,6 +19,15 @@ module Hashie
end
private_class_method :requires_class_methods?
+ def to_h
+ defaults = ::Hash[self.class.properties.map do |prop|
+ [Hashie::Extensions::IndifferentAccess.convert_key(prop), self.class.defaults[prop]]
+ end]
+
+ defaults.merge(self)
+ end
+ alias to_hash to_h
+
module ClassMethods
# Check to see if the specified property has already been
# defined.
diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb
index c2c7888..7702c14 100644
--- a/lib/hashie/extensions/indifferent_access.rb
+++ b/lib/hashie/extensions/indifferent_access.rb
@@ -25,6 +25,11 @@ module Hashie
module IndifferentAccess
include Hashie::Extensions::RubyVersionCheck
+ # @api private
+ def self.convert_key(key)
+ key.to_s
+ end
+
def self.included(base)
Hashie::Extensions::Dash::IndifferentAccess.maybe_extend(base)
@@ -68,7 +73,7 @@ module Hashie
end
def convert_key(key)
- key.to_s
+ IndifferentAccess.convert_key(key)
end
# Iterates through the keys and values, reconverting them to