-
Notifications
You must be signed in to change notification settings - Fork 425
Clean up multi_to_json #174
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -43,9 +43,20 @@ def rescue | |
| end | ||
| end | ||
|
|
||
| def self.logger(device=nil) | ||
| return @logger = Logger.new(device) if device | ||
| @logger ||= Logger.new(IO::NULL) | ||
| def self.to_json(object) | ||
| _fast_to_json(object) | ||
| rescue NameError | ||
| define_to_json(FastJsonapi::MultiToJson) | ||
| _fast_to_json(object) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def self.define_to_json(receiver) | ||
| cl = caller_locations[0] | ||
| method_body = to_json_method | ||
| logger.debug { "Defining #{receiver}._fast_to_json as #{method_body.inspect}" } | ||
| receiver.instance_eval method_body, cl.absolute_path, cl.lineno | ||
| end | ||
|
|
||
| # Encoder-compatible with default MultiJSON adapters and defaults | ||
|
|
@@ -76,23 +87,9 @@ def self.to_json_method | |
| encode_method << "\nend" | ||
| end | ||
|
|
||
| def self.to_json(object) | ||
| _fast_to_json(object) | ||
| rescue NameError | ||
| define_to_json(FastJsonapi::MultiToJson) | ||
| _fast_to_json(object) | ||
| end | ||
|
|
||
| def self.define_to_json(receiver) | ||
| cl = caller_locations[0] | ||
| method_body = to_json_method | ||
| logger.debug { "Defining #{receiver}._fast_to_json as #{method_body.inspect}" } | ||
| receiver.instance_eval method_body, cl.absolute_path, cl.lineno | ||
| end | ||
|
|
||
| def self.reset_to_json! | ||
| undef :_fast_to_json if method_defined?(:_fast_to_json) | ||
| logger.debug { "Undefining #{receiver}._fast_to_json" } | ||
|
Contributor
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. ❓ It's not used in the normal lifecycle of the app and because there's no test in the suite, but I wouldn't say it serves no purpose. Especially if this module were made I do have some tests I started writing in https://github.com/bf4/fast_multi_json but they didn't cover this specifically |
||
| def self.logger(device=nil) | ||
| return @logger = Logger.new(device) if device | ||
| @logger ||= Logger.new(IO::NULL) | ||
| 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.
I think what you might mean here is to apply
# @api privateto the below methods, which I disagree with. It might make more sense to document intended usage, but I would say this is all a stable public API.The private keyword has no effect on the interface.
In any case, the argument I can see for declaring it
# @api privatewould be to say to anyone using the library not to rely on those methods being there, whether or not their public. (In Ruby, nothing's really private anyhow).