camel_snake_keys

Gem Version Build Status Dependency Status Coverage Status

Add recursive with_snake_keys and with_camel_keys refinements to Array and Hash. Preserve strings and symbols and treat hash descendents such as ActiveSupport::HashWithIndifferentAccess and Hashie::Mash agnostically.

Documentation

Add gem 'camel_snake_keys' to your Gemfile or gem install camel_snake_keys. Where you want to add with_snake_keys and with_camel_keys to your objects invoke using CamelSnakeKeys, or invoke the class methods, CamelSnakeKeys.camel_keys(object, with_indifference) and CamelSnakeKeys.snake_keys(object, with_indifference).

If with_indifference is set to a true value hashes will be returned as ActiveSupport's HashWithIndifferentAccess.

require 'camel_snake_keys'

using CamelSnakeKeys

{fooBar: "Frob"}.with_snake_keys
=> {:foo_bar=>"Frob"}

[{:foo_bar=>"Frob"}].with_camel_keys
=> [{fooBar: "Frob"}]