Skip to content

Commit cdab838

Browse files
author
Julian Todt
committed
fix rubocop issues
1 parent c9d12cd commit cdab838

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

lib/puppet/functions/mysql/deepmerge.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# When there are conficting uses of dashes and underscores in two keys (which mysql would otherwise equate),
1313
# the rightmost style will win.
1414
Puppet::Functions.create_function(:'mysql::deepmerge') do
15-
1615
def deepmerge(*args)
1716
if args.length < 2
1817
raise Puppet::ParseError, _('mysql_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length }
@@ -34,7 +33,7 @@ def deepmerge(*args)
3433
# and repeating the process.
3534
overlay(result, current)
3635
end
37-
return(result)
36+
result
3837
end
3938

4039
def normalized?(hash, key)
@@ -57,14 +56,11 @@ def overlay(hash1, hash2)
5756
end
5857

5958
def deep_copy(inputhash)
60-
if !inputhash.is_a? Hash
61-
return inputhash
62-
else
63-
hash = Hash.new
64-
inputhash.each do |k,v|
65-
hash.store(k, deep_copy(v))
66-
end
67-
return hash
59+
return inputhash unless inputhash.is_a? Hash
60+
hash = {}
61+
inputhash.each do |k, v|
62+
hash.store(k, deep_copy(v))
6863
end
64+
hash
6965
end
7066
end

lib/puppet/functions/mysql/dirname.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
end
77

88
def dirname(path)
9-
return '' if path == nil
10-
return File.dirname(path)
9+
return '' if path.nil?
10+
File.dirname(path)
1111
end
1212
end

spec/functions/mysql_deepmerge_spec.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'mysql::deepmerge' do
5+
describe 'mysql::deepmerge' do
66
it 'exists' do
77
is_expected.not_to eq(nil)
88
end
@@ -12,7 +12,7 @@
1212
end
1313

1414
it 'throws error with only one argument' do
15-
is_expected.to run.with_params({ 'one' => 1 }).and_raise_error(Puppet::ParseError)
15+
is_expected.to run.with_params('one' => 1).and_raise_error(Puppet::ParseError)
1616
end
1717

1818
it 'accepts empty strings as puppet undef' do
@@ -22,14 +22,14 @@
2222
index_values = %w[one two three]
2323
expected_values_one = %w[1 2 2]
2424
it 'is able to mysql_deepmerge two hashes' do
25-
new_hash = subject.execute({ 'one' => '1', 'two' => '1' }, { 'two' => '2', 'three' => '2' })
25+
new_hash = subject.execute({ 'one' => '1', 'two' => '1' }, 'two' => '2', 'three' => '2')
2626
index_values.each_with_index do |index, expected|
2727
expect(new_hash[index]).to eq(expected_values_one[expected])
2828
end
2929
end
3030

3131
it 'mysql_deepmerges multiple hashes' do
32-
hash = subject.execute({ 'one' => 1 }, { 'one' => '2' }, { 'one' => '3' })
32+
hash = subject.execute({ 'one' => 1 }, { 'one' => '2' }, 'one' => '3')
3333
expect(hash['one']).to eq('3')
3434
end
3535

@@ -39,20 +39,20 @@
3939

4040
expected_values_two = [1, 2, 'four' => 4]
4141
it 'mysql_deepmerges subhashes' do
42-
hash = subject.execute({ 'one' => 1 }, { 'two' => 2, 'three' => { 'four' => 4 } })
42+
hash = subject.execute({ 'one' => 1 }, 'two' => 2, 'three' => { 'four' => 4 })
4343
index_values.each_with_index do |index, expected|
4444
expect(hash[index]).to eq(expected_values_two[expected])
4545
end
4646
end
4747

4848
it 'appends to subhashes' do
49-
hash = subject.execute({ 'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } })
49+
hash = subject.execute({ 'one' => { 'two' => 2 } }, 'one' => { 'three' => 3 })
5050
expect(hash['one']).to eq('two' => 2, 'three' => 3)
5151
end
5252

5353
expected_values_three = [1, 'dos', { 'four' => 4, 'five' => 5 }]
5454
it 'appends to subhashes 2' do
55-
hash = subject.execute({ 'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, { 'two' => 'dos', 'three' => { 'five' => 5 } })
55+
hash = subject.execute({ 'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, 'two' => 'dos', 'three' => { 'five' => 5 })
5656
index_values.each_with_index do |index, expected|
5757
expect(hash[index]).to eq(expected_values_three[expected])
5858
end
@@ -61,18 +61,18 @@
6161
index_values_two = %w[key1 key2]
6262
expected_values_four = [{ 'a' => 1, 'b' => 99 }, 'c' => 3]
6363
it 'appends to subhashes 3' do
64-
hash = subject.execute({ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } })
64+
hash = subject.execute({ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, 'key1' => { 'b' => 99 })
6565
index_values_two.each_with_index do |index, expected|
6666
expect(hash[index]).to eq(expected_values_four[expected])
6767
end
6868
end
6969

7070
it 'equates keys mod dash and underscore #value' do
71-
hash = subject.execute({ 'a-b-c' => 1 }, { 'a_b_c' => 10 })
71+
hash = subject.execute({ 'a-b-c' => 1 }, 'a_b_c' => 10)
7272
expect(hash['a_b_c']).to eq(10)
7373
end
7474
it 'equates keys mod dash and underscore #not' do
75-
hash = subject.execute({ 'a-b-c' => 1 }, { 'a_b_c' => 10 })
75+
hash = subject.execute({ 'a-b-c' => 1 }, 'a_b_c' => 10)
7676
expect(hash).not_to have_key('a-b-c')
7777
end
7878

@@ -81,11 +81,11 @@
8181
index_values_error = ['a-b-c', 'b_c_d']
8282
index_values_three.each_with_index do |index, expected|
8383
it 'keeps style of the last when keys are equal mod dash and underscore #value' do
84-
hash = subject.execute({ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 } }, { 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 } })
84+
hash = subject.execute({ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 } }, 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 })
8585
expect(hash[index]).to eq(expected_values_five[expected])
8686
end
8787
it 'keeps style of the last when keys are equal mod dash and underscore #not' do
88-
hash = subject.execute({ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 } }, { 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 } })
88+
hash = subject.execute({ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 } }, 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 })
8989
expect(hash).not_to have_key(index_values_error[expected])
9090
end
9191
end

spec/functions/mysql_strip_hash_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
end
1111

1212
it 'raises a ArgumentError if there is more than 1 arguments' do
13-
is_expected.to run.with_params({'foo' => 1}, {'bar' => 2}).and_raise_error(ArgumentError)
13+
is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(ArgumentError)
1414
end
1515

1616
it 'raises a ArgumentError if argument is not a hash' do
1717
is_expected.to run.with_params('foo').and_raise_error(ArgumentError)
1818
end
1919

2020
it 'passes a hash without blanks through' do
21-
is_expected.to run.with_params({'one' => 1, 'two' => 2, 'three' => 3}).and_return({'one' => 1, 'two' => 2, 'three' => 3})
21+
is_expected.to run.with_params('one' => 1, 'two' => 2, 'three' => 3).and_return('one' => 1, 'two' => 2, 'three' => 3)
2222
end
2323

2424
it 'removes blank hash elements' do
25-
is_expected.to run.with_params({'one' => 1, 'two' => '', 'three' => nil, 'four' => 4}).and_return({"one"=>1, "three"=>nil, "four"=>4})
25+
is_expected.to run.with_params('one' => 1, 'two' => '', 'three' => nil, 'four' => 4).and_return('one' => 1, 'three' => nil, 'four' => 4)
2626
end
2727
end

0 commit comments

Comments
 (0)