module Mongoid::Attributes::Embedded

def traverse(attributes, path)

Returns:
  • (Object | nil) - The attributes at the given path,

Parameters:
  • path (String) -- The dot notation string.
  • attributes (Hash) -- The document attributes.

Other tags:
    Example: Fetch an embedded value via dot notation. -
def traverse(attributes, path)
  path.split('.').each do |key|
    break if attributes.nil?
    attributes = if attributes.try(:key?, key)
                   attributes[key]
                 elsif attributes.respond_to?(:each) && key.match?(/\A\d+\z/)
                   attributes[key.to_i]
                 end
  end
  attributes
end