0.0
No release in over 3 years
Utility methods such as deep_copy, dig, bury, delete, and path? for working with PORO structures arbitrarily nested with Hashes and Arrays.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

nested_objects gem

Gem Version Build Status Documentation Change Log Slack

The NestedObjects module provides module methods to safely navigate and manage a heirarchy of Ruby POROs nested using Hashes or Arrays. Think of these nested data objects like what you would get after reading in a JSON file.

Usage

Module Methods

These methods are exposted on the NestedObjects module. The key methods are: deep_copy, dig, bury, delete, and path?.

Here is an example of using the dig method:

require 'nested_objects'

data = { 'people' => [{ 'name' => 'John'}, { 'name' => 'Jane' }] }
path = 'people/0/name'.split('/')
NestedObjects.dig(data, path) #=> 'John'

See documentation and examples of the full API in the gem's YARD documentation.

Object Mixin

As a convenience, these methods can be mixed into other classes by including the NestedObjects::Mixin module.

In order to reduce the possibility of method name conflicts, all methods are prefixed with nested_.

require 'nested_objects'

Object.include NestedObjects::Mixin

data = { 'people' => [{ 'name' => 'John'}, { 'name' => 'Jane' }] }
path = 'people/0/name'.split('/')
data.nested_dig(path) #=> 'John'

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake to run tests, static analysis, and build the gem.

For experimentation, you can also run bin/console for an interactive (IRB) prompt that automatically requires nested_objects.

Contributing

See the contributing guildlines for guidance on how to contriute to this project.