-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration with camelizing keys #160
base: master
Are you sure you want to change the base?
Changes from all commits
25d9bda
0750734
cae6566
5de2c2d
eb0f81d
2771ee9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ | |
node_modules | ||
|
||
/docs/build/ | ||
.DS_Store | ||
.cache/ | ||
.docusaurus/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have documentation for this, can you please add? If not, I'll add after this PR will be merged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is small documentation with example in lib/panko_serializer.rb how to use it but probably you can add any documentation later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was talking about the documentation here: https://github.com/yosiat/panko_serializer/tree/master/docs |
||
|
||
module Panko | ||
class Configuration | ||
InitializeError = Class.new(StandardError) | ||
|
||
CAMEL_CASE_LOWER = "camelCase" | ||
CAMEL_CASE = "CamelCase" | ||
AVAILABLE_KEY_TYPES = [CAMEL_CASE_LOWER, CAMEL_CASE].freeze | ||
|
||
attr_reader :key_type | ||
|
||
def initialize | ||
@key_type = nil | ||
end | ||
|
||
def key_type=(value) | ||
raise InitializeError, "Invalid key type" unless AVAILABLE_KEY_TYPES.include?(key_type) | ||
|
||
@key_type = value | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we handle the case where
key_type
is nil and just return the name as is?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and looks like I have added check before method calling
if Panko.configuration.key_type
, but I'll add in any caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I think about memoization at this point, what do you think?
if developer serializes 1000 elements with the same key, no need to transform key 1000 times, 1 is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if Panko.configuration.key_type
inself.create
, we already handle intransform_key
now.and I think about memoization at this point, what do you think?
- I don't think it's necessary, since attributes are creating when serializer is defined and not during serialization time, so you pay the "transformation cost" only at boot time.