[chef] chef-helpers: deep attribute access by JSONPath


Chronological Thread 
  • From: Maciej Pasternacki < >
  • To:
  • Subject: [chef] chef-helpers: deep attribute access by JSONPath
  • Date: Mon, 22 Jul 2013 12:07:00 +0200

Hi,

FWIW, I've released a new version of chef-helpers.gem - my collection of utils and extra methods I use in recipes. It's available at https://github.com/3ofcoins/chef-helpers/

One feature that may be particularly useful (and if it's interesting, it may be worth extracting to a separate gem) is overloading Chef::Node#[] to allow reading nested attributes using JSONPath notation (http://goessner.net/articles/JsonPath/):

    chef > require 'chef-helpers'
     => true 
    chef > node['$..name']
     => ["portinari-2.local", "Java(TM) SE Runtime Environment", "Java HotSpot(TM) 64-Bit Server VM", "Darwin"] 
    chef > node['$.kernel.name']
     => ["Darwin"] 

You can read about more sophisticated use cases at http://3ofcoins.net/2013/07/21/access-chef-nodes-attributes-by-jsonpath/ - I bump into such situations quite often, and easy access to deep attributes saves me a lot of effort (and prevents confusing tracebacks if the code is not defensive enough). I'm curious to hear your thoughts.

-- M



Archive powered by MHonArc 2.6.16.

§