-
Notifications
You must be signed in to change notification settings - Fork 2.2k
(#22792) rename 'select' to 'filter' #1988
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
Merged
joshcooper
merged 5 commits into
puppetlabs:master
from
hlindberg:issues/issue-22792-rename-select
Oct 14, 2013
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed6916b
(#22792) Rename the 'select' function to 'filter'
hlindberg a82fa5c
(#22792) Add select function that raises error
hlindberg 4085ff4
(#22792) Rename 'select' to 'filter' in spec tests
hlindberg a461eff
(#22792) Fix typo in filter functions documentation.
hlindberg 5168912
(#22792) Rename select_spec.rb to filter_spec.rb
hlindberg 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 hidden or 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,48 @@ | ||
| require 'puppet/parser/ast/lambda' | ||
|
|
||
| Puppet::Parser::Functions::newfunction( | ||
| :filter, | ||
| :type => :rvalue, | ||
| :arity => 2, | ||
| :doc => <<-'ENDHEREDOC') do |args| | ||
| Applies a parameterized block to each element in a sequence of entries from the first | ||
| argument and returns an array or hash (same type as left operand) | ||
| with the entries for which the block evaluates to true. | ||
|
|
||
| This function takes two mandatory arguments: the first should be an Array or a Hash, and the second | ||
| a parameterized block as produced by the puppet syntax: | ||
|
|
||
| $a.filter |$x| { ... } | ||
|
|
||
| When the first argument is an Array, the block is called with each entry in turn. When the first argument | ||
| is a Hash the entry is an array with `[key, value]`. | ||
|
|
||
| The returned filtered object is of the same type as the receiver. | ||
|
|
||
| *Examples* | ||
|
|
||
| # selects all that end with berry | ||
| $a = ["raspberry", "blueberry", "orange"] | ||
| $a.filter |$x| { $x =~ /berry$/ } | ||
|
|
||
| - Since 3.4 | ||
| - requires `parser = future`. | ||
| ENDHEREDOC | ||
|
|
||
| receiver = args[0] | ||
| pblock = args[1] | ||
|
|
||
| raise ArgumentError, ("filter(): wrong argument type (#{pblock.class}; must be a parameterized block.") unless pblock.is_a? Puppet::Parser::AST::Lambda | ||
|
|
||
| case receiver | ||
| when Array | ||
| receiver.select {|x| pblock.call(self, x) } | ||
| when Hash | ||
| result = receiver.select {|x, y| pblock.call(self, [x, y]) } | ||
| # Ruby 1.8.7 returns Array | ||
| result = Hash[result] unless result.is_a? Hash | ||
| result | ||
| else | ||
| raise ArgumentError, ("filter(): wrong argument type (#{receiver.class}; must be an Array or a Hash.") | ||
| end | ||
| end |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,47 +1,15 @@ | ||
| require 'puppet/parser/ast/lambda' | ||
|
|
||
| Puppet::Parser::Functions::newfunction( | ||
| :select, | ||
| :type => :rvalue, | ||
| :arity => 2, | ||
| :doc => <<-'ENDHEREDOC') do |args| | ||
| Applies a parameterized block to each element in a sequence of entries from the first | ||
| argument and returns an array with the entires for which the block evaluates to true. | ||
|
|
||
| This function takes two mandatory arguments: the first should be an Array or a Hash, and the second | ||
| a parameterized block as produced by the puppet syntax: | ||
|
|
||
| $a.select |$x| { ... } | ||
|
|
||
| When the first argument is an Array, the block is called with each entry in turn. When the first argument | ||
| is a hash the entry is an array with `[key, value]`. | ||
|
|
||
| The returned filtered object is of the same type as the receiver. | ||
| The 'select' function has been renamed to 'filter'. Please update your manifests. | ||
|
|
||
| *Examples* | ||
|
|
||
| # selects all that end with berry | ||
| $a = ["raspberry", "blueberry", "orange"] | ||
| $a.select |$x| { $x =~ /berry$/ } | ||
|
|
||
| - Since 3.2 | ||
| The select function is reserved for future use. | ||
| - Removed as of 3.4 | ||
| - requires `parser = future`. | ||
| ENDHEREDOC | ||
|
|
||
| receiver = args[0] | ||
| pblock = args[1] | ||
|
|
||
| raise ArgumentError, ("select(): wrong argument type (#{pblock.class}; must be a parameterized block.") unless pblock.is_a? Puppet::Parser::AST::Lambda | ||
|
|
||
| case receiver | ||
| when Array | ||
| receiver.select {|x| pblock.call(self, x) } | ||
| when Hash | ||
| result = receiver.select {|x, y| pblock.call(self, [x, y]) } | ||
| # Ruby 1.8.7 returns Array | ||
| result = Hash[result] unless result.is_a? Hash | ||
| result | ||
| else | ||
| raise ArgumentError, ("select(): wrong argument type (#{receiver.class}; must be an Array or a Hash.") | ||
| end | ||
| end | ||
| raise NotImplementedError, | ||
| "The 'select' function has been renamed to 'filter'. Please update your manifests." | ||
| end |
This file contains hidden or 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
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.
since we've renamed select.rb -> filter.rb, how about:
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.
missed that - fixing