lib/lotus/utils/attributes.rb in lotus-utils-0.4.0 vs lib/lotus/utils/attributes.rb in lotus-utils-0.4.1
- old
+ new
@@ -108,10 +108,27 @@
#
# @since 0.3.2
#
# @see Lotus::Utils::Hash
def to_h
- @attributes.deep_dup
+ Utils::Hash.new.tap do |result|
+ @attributes.each do |k, v|
+ result[k] = _read_value(v)
+ end
+ end
+ end
+
+ private
+
+ # @since 0.4.1
+ # @api private
+ def _read_value(value)
+ case val = value
+ when ::Hash, ::Lotus::Utils::Hash, ->(v) { v.respond_to?(:lotus_nested_attributes?) }
+ val.to_h
+ else
+ val
+ end
end
end
end
end