Move transforms mapping to constant
This commit is contained in:
parent
fd17386b51
commit
e4c65a2567
@ -17,6 +17,12 @@ module FastJsonapi
|
|||||||
|
|
||||||
SERIALIZABLE_HASH_NOTIFICATION = 'render.fast_jsonapi.serializable_hash'
|
SERIALIZABLE_HASH_NOTIFICATION = 'render.fast_jsonapi.serializable_hash'
|
||||||
SERIALIZED_JSON_NOTIFICATION = 'render.fast_jsonapi.serialized_json'
|
SERIALIZED_JSON_NOTIFICATION = 'render.fast_jsonapi.serialized_json'
|
||||||
|
TRANSFORMS_MAPPING = {
|
||||||
|
camel: :camelize,
|
||||||
|
camel_lower: [:camelize, :lower],
|
||||||
|
dash: :dasherize,
|
||||||
|
underscore: :underscore
|
||||||
|
}.freeze
|
||||||
|
|
||||||
included do
|
included do
|
||||||
# Set record_type based on the name of the serializer class
|
# Set record_type based on the name of the serializer class
|
||||||
@ -137,13 +143,7 @@ module FastJsonapi
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_key_transform(transform_name)
|
def set_key_transform(transform_name)
|
||||||
mapping = {
|
self.transform_method = TRANSFORMS_MAPPING[transform_name.to_sym]
|
||||||
camel: :camelize,
|
|
||||||
camel_lower: [:camelize, :lower],
|
|
||||||
dash: :dasherize,
|
|
||||||
underscore: :underscore
|
|
||||||
}
|
|
||||||
self.transform_method = mapping[transform_name.to_sym]
|
|
||||||
|
|
||||||
# ensure that the record type is correctly transformed
|
# ensure that the record type is correctly transformed
|
||||||
if record_type
|
if record_type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user