-
Notifications
You must be signed in to change notification settings - Fork 983
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
Fixes #3309 - Support deep merging of hash and array structures in smart class parameters #1715
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20140826104209_add_merge_overrides_and_avoid_duplicates_to_lookup_key.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddMergeOverridesAndAvoidDuplicatesToLookupKey < ActiveRecord::Migration | ||
def change | ||
add_column :lookup_keys, :merge_overrides, :boolean | ||
add_column :lookup_keys, :avoid_duplicates, :boolean | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,4 @@ nine: | |
puppetclass: three | ||
environment: global_puppetmaster | ||
lookup_key_id: nil | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This method is hard to read (not you fault) and you're adding more complexity. Therefore I'd consider doing some refactorings. First - you can extract
values[key_id][name]
into some variable so you don't have to repeat it on every line.Then you can use hash with default values
values = Hash.new {|h, k| h[k] = {}; values[:new_key][name] = triplet
so you avoidhash[key_id] ||= {}
lines.Furthermore you don't have to store values_for_deep_merge in this complex hash format. I'd suggest using array OpenStruct or Struct instance for keeping value, index, element and element_name. Then calling
hash_deep_merge
that will generate values in desired hash structure. The benefit is thathash_deep_merge
will be much easier to read. Ideally I'd use OpenStruct in wholevalues_hash
method and convert the result into hash at the end (maybe some convert method).Also I think you should compute values inside
when "hash"
branch, not looking atvalues_for_deep_merge
outside of hash context in unless condition (this will also eliminate the need ofvalues_for_deep_merge
being global to the whole method).Last but not least, I'd split this method so the actual evaluation is separated per type so we'd have methods like update_array_matcher, update_hash_matcher, update_generic_matcher which can be tested separately.
Let me know if I should elaborate any of previous refactorings. This file would deserves many other improvements but these are not related to the PR.