module JSONAPIHelpers::KeyTransform

Public Instance Methods

call(object, key_transform: nil) click to toggle source
# File lib/jsonapi_helpers/support/key_transform.rb, line 11
def call(object, key_transform: nil)
  key_transform ||= JSONAPIHelpers.config.key_transform
  public_send(key_transform, object)
end
camel(value) click to toggle source

Transforms values to UpperCamelCase or PascalCase.

@example:

"some_key" => "SomeKey",
# File lib/jsonapi_helpers/support/key_transform.rb, line 20
def camel(value)
  case value
  when Hash then value.deep_transform_keys! { |key| camel(key) }
  when Symbol then camel(value.to_s).to_sym
  when String then StringSupport.camel(value)
  else value
  end
end
camel_lower(value) click to toggle source

Transforms values to camelCase.

@example:

"some_key" => "someKey",
# File lib/jsonapi_helpers/support/key_transform.rb, line 33
def camel_lower(value)
  case value
  when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
  when Symbol then camel_lower(value.to_s).to_sym
  when String then StringSupport.camel_lower(value)
  else value
  end
end
dash(value) click to toggle source

Transforms values to dashed-case. This is the default case for the JsonApi adapter.

@example:

"some_key" => "some-key",
# File lib/jsonapi_helpers/support/key_transform.rb, line 47
def dash(value)
  case value
  when Hash then value.deep_transform_keys! { |key| dash(key) }
  when Symbol then dash(value.to_s).to_sym
  when String then StringSupport.dash(value)
  else value
  end
end
unaltered(value) click to toggle source

Returns the value unaltered

# File lib/jsonapi_helpers/support/key_transform.rb, line 71
def unaltered(value)
  value
end
underscore(value) click to toggle source

Transforms values to underscore_case. This is the default case for deserialization in the JsonApi adapter.

@example:

"some-key" => "some_key",
# File lib/jsonapi_helpers/support/key_transform.rb, line 61
def underscore(value)
  case value
  when Hash then value.deep_transform_keys! { |key| underscore(key) }
  when Symbol then underscore(value.to_s).to_sym
  when String then StringSupport.underscore(value)
  else value
  end
end