Module: Mongoid::Attributes::Embedded
Relationships & Source Files | |
Defined in: | lib/mongoid/attributes/embedded.rb |
Overview
Utility module for working with embedded attributes.
Instance Method Summary
-
#traverse(attributes, path) ⇒ Object | nil
Fetch an embedded value or subset of attributes via dot notation.
Instance Method Details
#traverse(attributes, path) ⇒ Object
| nil
Fetch an embedded value or subset of attributes via dot notation.
# File 'lib/mongoid/attributes/embedded.rb', line 20
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