Skip to content

Commit c6823f9

Browse files
author
David Swan
committed
Rubocop Implemented
1 parent baf3a0f commit c6823f9

27 files changed

+1946
-2490
lines changed

.rubocop.yml

Lines changed: 89 additions & 497 deletions
Large diffs are not rendered by default.

.rubocop_todo.yml

Whitespace-only changes.

.sync.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ NOTICE:
33
unmanaged: true
44
appveyor.yml:
55
delete: true
6+
.travis.yml:
7+
extras:
8+
- rvm: 2.1.9
9+
script: bundle exec rake rubocop

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ matrix:
2828
- rvm: 2.1.9
2929
bundler_args: --without system_tests
3030
env: PUPPET_GEM_VERSION="~> 4.0"
31+
- rvm: 2.1.9
32+
script: bundle exec rake rubocop
3133
notifications:
3234
email: false

lib/puppet/parser/functions/create_ini_settings.rb

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
#
22
# create_ini_settings.rb
33
#
4-
54
module Puppet::Parser::Functions
6-
newfunction(:create_ini_settings, :type => :statement, :doc => <<-EOS
7-
Uses create_resources to create a set of ini_setting resources from a hash:
5+
newfunction(:create_ini_settings, type: :statement, doc: <<-EOS
6+
Uses create_resources to create a set of ini_setting resources from a hash:
87
9-
$settings = { section1 => {
10-
setting1 => val1
11-
},
12-
section2 => {
13-
setting2 => val2,
14-
setting3 => {
15-
ensure => absent
8+
$settings = { section1 => {
9+
setting1 => val1
10+
},
11+
section2 => {
12+
setting2 => val2,
13+
setting3 => {
14+
ensure => absent
15+
}
16+
}
17+
}
18+
$defaults = {
19+
path => '/tmp/foo.ini'
1620
}
17-
}
18-
}
19-
$defaults = {
20-
path => '/tmp/foo.ini'
21-
}
22-
create_ini_settings($settings,$defaults)
21+
create_ini_settings($settings,$defaults)
2322
2423
25-
Will create the following resources
24+
Will create the following resources
2625
27-
ini_setting{'/tmp/foo.ini [section1] setting1':
28-
ensure => present,
29-
section => 'section1',
30-
setting => 'setting1',
31-
value => 'val1',
32-
path => '/tmp/foo.ini',
33-
}
34-
ini_setting{'/tmp/foo.ini [section2] setting2':
35-
ensure => present,
36-
section => 'section2',
37-
setting => 'setting2',
38-
value => 'val2',
39-
path => '/tmp/foo.ini',
40-
}
41-
ini_setting{'/tmp/foo.ini [section2] setting3':
42-
ensure => absent,
43-
section => 'section2',
44-
setting => 'setting3',
45-
path => '/tmp/foo.ini',
46-
}
26+
ini_setting{'/tmp/foo.ini [section1] setting1':
27+
ensure => present,
28+
section => 'section1',
29+
setting => 'setting1',
30+
value => 'val1',
31+
path => '/tmp/foo.ini',
32+
}
33+
ini_setting{'/tmp/foo.ini [section2] setting2':
34+
ensure => present,
35+
section => 'section2',
36+
setting => 'setting2',
37+
value => 'val2',
38+
path => '/tmp/foo.ini',
39+
}
40+
ini_setting{'/tmp/foo.ini [section2] setting3':
41+
ensure => absent,
42+
section => 'section2',
43+
setting => 'setting3',
44+
path => '/tmp/foo.ini',
45+
}
4746
48-
EOS
49-
) do |arguments|
47+
EOS
48+
) do |arguments|
5049

51-
raise(Puppet::ParseError, "create_ini_settings(): Wrong number of arguments " +
52-
"given (#{arguments.size} for 1 or 2)") unless arguments.size.between?(1,2)
50+
unless arguments.size.between?(1, 2)
51+
raise(Puppet::ParseError, 'create_ini_settings(): Wrong number of arguments ' \
52+
"given (#{arguments.size} for 1 or 2)")
53+
end
5354

5455
settings = arguments[0]
5556
defaults = arguments[1] || {}
5657

57-
if [settings,defaults].any?{|i| !i.is_a?(Hash) }
58+
if [settings, defaults].any? { |i| !i.is_a?(Hash) }
5859
raise(Puppet::ParseError,
59-
'create_ini_settings(): Requires all arguments to be a Hash')
60+
'create_ini_settings(): Requires all arguments to be a Hash')
6061
end
6162

62-
resources = settings.keys.inject({}) do |res, section|
63-
raise(Puppet::ParseError,
64-
"create_ini_settings(): Section #{section} must contain a Hash") \
65-
unless settings[section].is_a?(Hash)
66-
67-
unless path = defaults.merge(settings)['path']
68-
raise Puppet::ParseError, 'create_ini_settings(): must pass the path parameter to the Ini_setting resource!'
63+
resources = settings.keys.each_with_object({}) do |section, res|
64+
unless settings[section].is_a?(Hash)
65+
raise(Puppet::ParseError,
66+
"create_ini_settings(): Section #{section} must contain a Hash")
6967
end
7068

69+
path = defaults.merge(settings)['path']
70+
raise Puppet::ParseError, 'create_ini_settings(): must pass the path parameter to the Ini_setting resource!' unless path
71+
7172
settings[section].each do |setting, value|
7273
res["#{path} [#{section}] #{setting}"] = {
7374
'ensure' => 'present',
7475
'section' => section,
7576
'setting' => setting,
7677
}.merge(if value.is_a?(Hash)
77-
value
78-
else
79-
{ 'value' => value, }
80-
end)
78+
value
79+
else
80+
{ 'value' => value }
81+
end)
8182
end
82-
res
8383
end
8484

8585
Puppet::Parser::Functions.function('create_resources')
86-
function_create_resources(['ini_setting',resources,defaults])
86+
function_create_resources(['ini_setting', resources, defaults])
8787
end
8888
end
8989

lib/puppet/provider/ini_setting/ruby.rb

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require File.expand_path('../../../util/ini_file', __FILE__)
22

33
Puppet::Type.type(:ini_setting).provide(:ruby) do
4-
54
def self.instances
65
# this code is here to support purging and the query-all functionality of the
76
# 'puppet resource' command, on a per-file basis. Users
@@ -12,25 +11,23 @@ def self.instances
1211
# declaration). This allows 'purging' to be used to clear out
1312
# all settings from a particular ini file except those included in
1413
# the catalog.
15-
if self.respond_to?(:file_path)
16-
# figure out what to do about the seperator
17-
ini_file = Puppet::Util::IniFile.new(file_path, '=')
18-
resources = []
19-
ini_file.section_names.each do |section_name|
20-
ini_file.get_settings(section_name).each do |setting, value|
21-
resources.push(
22-
new(
23-
:name => namevar(section_name, setting),
24-
:value => value,
25-
:ensure => :present
26-
)
27-
)
28-
end
14+
raise(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded') unless respond_to?(:file_path)
15+
16+
# figure out what to do about the seperator
17+
ini_file = Puppet::Util::IniFile.new(file_path, '=')
18+
resources = []
19+
ini_file.section_names.each do |section_name|
20+
ini_file.get_settings(section_name).each do |setting, value|
21+
resources.push(
22+
new(
23+
name: namevar(section_name, setting),
24+
value: value,
25+
ensure: :present,
26+
),
27+
)
2928
end
30-
resources
31-
else
32-
raise(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded')
3329
end
30+
resources
3431
end
3532

3633
def self.namevar(section_name, setting)
@@ -57,7 +54,7 @@ def value
5754
ini_file.get_value(section, setting)
5855
end
5956

60-
def value=(value)
57+
def value=(_value)
6158
ini_file.set_value(section, setting, separator, resource[:value])
6259
ini_file.save
6360
end
@@ -127,8 +124,8 @@ def indent_width
127124
end
128125

129126
private
127+
130128
def ini_file
131129
@ini_file ||= Puppet::Util::IniFile.new(file_path, separator, section_prefix, section_suffix, indent_char, indent_width)
132130
end
133-
134131
end

lib/puppet/provider/ini_subsetting/ruby.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
require File.expand_path('../../../util/setting_value', __FILE__)
33

44
Puppet::Type.type(:ini_subsetting).provide(:ruby) do
5-
65
def exists?
76
setting_value.get_subsetting_value(subsetting, resource[:use_exact_match])
87
end
98

109
def create
1110
setting_value.add_subsetting(
12-
subsetting, resource[:value], resource[:use_exact_match],
13-
resource[:insert_type], resource[:insert_value]
11+
subsetting, resource[:value], resource[:use_exact_match],
12+
resource[:insert_type], resource[:insert_value]
1413
)
1514
ini_file.set_value(section, setting, key_val_separator, setting_value.get_value)
1615
ini_file.save
@@ -32,8 +31,8 @@ def value
3231

3332
def value=(value)
3433
setting_value.add_subsetting(
35-
subsetting, value, resource[:use_exact_match],
36-
resource[:insert_type], resource[:insert_value]
34+
subsetting, value, resource[:use_exact_match],
35+
resource[:insert_type], resource[:insert_value]
3736
)
3837
ini_file.set_value(section, setting, key_val_separator, setting_value.get_value)
3938
ini_file.save
@@ -72,15 +71,15 @@ def quote_char
7271
end
7372

7473
private
74+
7575
def ini_file
7676
@ini_file ||= Puppet::Util::IniFile.new(file_path, key_val_separator)
7777
end
7878

7979
def setting_value
8080
@setting_value ||= Puppet::Util::SettingValue.new(
81-
ini_file.get_value(section, setting),
82-
subsetting_separator, quote_char, subsetting_key_val_separator
81+
ini_file.get_value(section, setting),
82+
subsetting_separator, quote_char, subsetting_key_val_separator
8383
)
8484
end
85-
8685
end

0 commit comments

Comments
 (0)