Module: CarrotRpc::Format

Defined in:
lib/carrot_rpc/format.rb

Overview

Used to format keys

Class Method Summary collapse

Class Method Details

.keys(format, data) ⇒ Hash

Logic to process the renaming of keys in a hash.

Parameters:

  • format (Symbol)

    :dasherize changes keys that have “_” to “-”

  • format (Symbol)

    :underscore changes keys that have “-” to “_”

  • format (Symbol)

    :skip, will not rename the keys

  • data (Hash)

    data structure to be transformed

Returns:

  • (Hash)

    the transformed data



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/carrot_rpc/format.rb', line 11

def self.keys(format, data)
  case format
  when :dasherize
    data.rename_keys("_", "-")
  when :underscore
    data.rename_keys("-", "_")
  when :none
    data
  else
    data
  end
end