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
Deep Merge Initializer Extension #382
base: master
Are you sure you want to change the base?
Conversation
I like it. You just need to fix the build ( |
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.
Just a couple changes to the change log and readme. I also have a thought experiment with the class_eval
for initialize
. Is that better or would a direct initialize
method be better?
@@ -13,7 +13,7 @@ scheme are considered to be bugs. | |||
### Added | |||
|
|||
* [#381](https://github.com/intridea/hashie/pull/381): Add a logging layer that lets us report potential issues to our users. As the first logged issue, report when a `Hashie::Mash` is attempting to overwrite a built-in method, since that is one of our number one questions - [@michaelherold](https://github.com/michaelherold). | |||
* Your contribution here. | |||
* [#382](https://github.com/intridea/hashie/pull/382): `DeepMergeInitializer` extension - [@sazor](https://github.com/sazor). |
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.
Please make sure to restore the "Your contribution here." line.
@@ -206,6 +206,10 @@ Hashie.stringify_keys hash # => Returns a copy of hash with keys stringified. | |||
|
|||
The MergeInitializer extension simply makes it possible to initialize a Hash subclass with another Hash, giving you a quick short-hand. | |||
|
|||
### DeepMergeInitializer | |||
|
|||
The DeepMergeInitializer acts the same as MergeInitializer but also cast all nested hashes to extendable class. |
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.
Please place the class names in backticks.
# | ||
module DeepMergeInitializer | ||
def self.included(base) | ||
base.class_eval do |
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.
Thought experiment: is doing class_eval
the right thing here? Would it be better to have initialize be an instance method that gets included?
|
||
it 'creates nested hash with the same type as parent hash' do | ||
s = subject.new({ a: :b, hash: { c: :d } })[:hash] | ||
pp s.class |
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.
pp ?
Great extension! just needed it today but found this PR is open for 3 years. @sazor to you want to pick it up? Otherwise I could try to fix the issues and open a new PR. |
I could fix it on this week. However, if you need it today or tomorrow then it's probably better for you to pick up. |
@sazor no pressure :D i've just pulled in your fork at the moment :) |
I bet this guy's almost done with this one! |
Idea of this extension came from #347 .