Skip to content

Commit 7fabc13

Browse files
authored
Merge pull request #1019 from tylerjl/hash-each-pair-return
Properly return objects in sorted hash each_pair
2 parents 38c4ae0 + 5a98781 commit 7fabc13

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Puppet 4.10.0 is the new minimum required version of Puppet.
99
#### Fixes
1010
* The Elasticsearch log directory is no longer recursively managed to avoid stomping on the user/mode settings that Elasticsearch prefers.
1111
* Package management on apt-based systems no longer encounters dependency errors when `manage_repo => false`.
12+
* An error related to elasticsearch_roles and `yield` errors has been fixed
1213
* Correctly permit instances to be set to `absent` without errors.
1314

1415
#### Features

lib/puppet_x/elastic/hash.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ def self.extended(base)
6464
# Override each_pair with a method that yields key/values in
6565
# sorted order.
6666
def each_pair
67+
return to_enum(:each_pair) unless block_given?
6768
keys.sort.each do |key|
6869
yield key, self[key]
6970
end
71+
self
7072
end
7173
end
7274
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
3+
4+
require 'spec_helper_rspec'
5+
require 'puppet_x/elastic/hash'
6+
7+
describe Puppet_X::Elastic::SortedHash do
8+
subject { { 'foo' => 1, 'bar' => 2 } }
9+
10+
describe 'each_pair' do
11+
it { is_expected.to respond_to :each_pair }
12+
13+
it 'yields values' do
14+
expect { |b| subject.each_pair(&b) }.to yield_control.exactly(2).times
15+
end
16+
17+
it 'returns an Enumerator if not passed a block' do
18+
expect(subject.each_pair).to be_an_instance_of(Enumerator)
19+
end
20+
21+
it 'returns values' do
22+
subject.each_pair.map { |k, v| [k, v] }.should == subject.to_a
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)