lib/hanami/utils/attributes.rb in hanami-utils-0.7.2 vs lib/hanami/utils/attributes.rb in hanami-utils-0.8.0
- old
+ new
@@ -64,14 +64,23 @@
# attributes.get(:unknown) # => nil
# attributes.get('unknown') # => nil
# attributes[:unknown] # => nil
# attributes['unknown'] # => nil
def get(attribute)
- @attributes[attribute.to_s]
+ value = @attributes
+
+ keys = attribute.to_s.split('.')
+ keys.each do |key|
+ break unless value
+
+ value = value[key]
+ end
+
+ value.is_a?(Hash) ? self.class.new(value) : value
end
# @since 0.3.4
- alias_method :[], :get
+ alias [] get
# Set the given value for the given attribute
#
# @param attribute [#to_s] a String or any object that implements #to_s
# @param value [Object] any value