Module: Axn::Internal::SubfieldPath
- Defined in:
- lib/axn/internal/subfield_path.rb
Overview
Pure utility functions for working with subfield paths (e.g., “user.profile.name”). These are stateless functions that operate only on their arguments.
Class Method Summary collapse
-
.navigate_to_parent(parent_value, path_parts) ⇒ Object
Navigates to the parent of the target field, creating intermediate hashes as needed.
-
.nested?(subfield) ⇒ Boolean
Checks if a subfield path contains nested access (e.g., “user.profile.name”).
-
.parse(subfield) ⇒ Object
Parses a subfield path into an array of parts.
-
.update_object(parent_value, subfield, new_value) ⇒ Object
Updates an object subfield using method assignment.
Class Method Details
.navigate_to_parent(parent_value, path_parts) ⇒ Object
Navigates to the parent of the target field, creating intermediate hashes as needed
21 22 23 24 25 |
# File 'lib/axn/internal/subfield_path.rb', line 21 def navigate_to_parent(parent_value, path_parts) path_parts[0..-2].reduce(parent_value) do |current, part| current[part.to_sym] || current[part] || (current[part.to_sym] = {}) end end |
.nested?(subfield) ⇒ Boolean
Checks if a subfield path contains nested access (e.g., “user.profile.name”)
11 12 13 |
# File 'lib/axn/internal/subfield_path.rb', line 11 def nested?(subfield) subfield.to_s.include?(".") end |
.parse(subfield) ⇒ Object
Parses a subfield path into an array of parts
16 17 18 |
# File 'lib/axn/internal/subfield_path.rb', line 16 def parse(subfield) subfield.to_s.split(".") end |
.update_object(parent_value, subfield, new_value) ⇒ Object
Updates an object subfield using method assignment
28 29 30 |
# File 'lib/axn/internal/subfield_path.rb', line 28 def update_object(parent_value, subfield, new_value) parent_value.public_send("#{subfield}=", new_value) end |