-
Notifications
You must be signed in to change notification settings - Fork 249
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
Attempt to look up non-existing settings in parent classes (see #21) #55
base: master
Are you sure you want to change the base?
Conversation
…an#21) This fixes an issue where settings are added to Cuba.settings *after* inheriting from `Cuba` are not picked up by the child classes. The problem is described in issue soveran#21. If a setting does not exist, Settings are looked up in the settings Hash of the parent class using `Hash#default_proc`. The settings Hash is still deepcloned, so settings are still overridable.
@@ -86,11 +86,26 @@ def self.settings | |||
end | |||
|
|||
def self.deepclone(obj) | |||
Marshal.load(Marshal.dump(obj)) | |||
# Hashes with a default_proc cannot be serialized by Marshal.dump. | |||
if obj.respond_to?(:default_proc) |
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'm curious. Why the respond_to?
?
{}.respond_to?(:default_proc) # => true
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 took a clue from the argument name (obj
). Because Cuba.deepclone
is part of the public API, this patch could break code that calls Cuba.deepclone
with anything other than a Hash.
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.
Nice. Thanks for replying :-)
I personally solved this issue without deep cloning via
I am using this cuba-plugin https://github.com/mkristian/cuba-api/blob/master/lib/cuba_api/config.rb |
I added a comment, please let me know what you guys think: #21 (comment) |
This fixes an issue where settings are added to Cuba.settings after inheriting from
Cuba
are not picked up by the child classes. The problem is described in issue #21.If a setting does not exist, settings are looked up in the settings Hash of the parent class using
Hash#default_proc
. The settings Hash is still deepcloned, so settings are still overridable.