pdk 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1336 -1329
- data/LICENSE +201 -201
- data/README.md +163 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -293
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -194
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -46
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -390
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -260
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -137
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -85
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -278
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -228
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2111 -2094
- metadata +3 -3
data/lib/pdk/config/ini_file.rb
CHANGED
@@ -1,183 +1,183 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
class Config
|
5
|
-
# Represents a configuration file using the INI file format
|
6
|
-
class IniFile < Namespace
|
7
|
-
# Ini Files have very strict valdiation rules which are set in the IniFileSetting class
|
8
|
-
# @see PDK::Config::Namespace.default_setting_class
|
9
|
-
def default_setting_class
|
10
|
-
PDK::Config::IniFileSetting
|
11
|
-
end
|
12
|
-
|
13
|
-
# Parses an IniFile document.
|
14
|
-
#
|
15
|
-
# @see PDK::Config::Namespace.parse_file
|
16
|
-
def parse_file(filename)
|
17
|
-
raise unless block_given?
|
18
|
-
data = load_data(filename)
|
19
|
-
return if data.nil? || data.empty?
|
20
|
-
|
21
|
-
ini_file = IniFileImpl.parse(data)
|
22
|
-
ini_file.to_hash.each do |name, value|
|
23
|
-
begin
|
24
|
-
new_setting = PDK::Config::IniFileSetting.new(name, self, value)
|
25
|
-
rescue StandardError
|
26
|
-
# We just ignore invalid initial settings
|
27
|
-
new_setting = PDK::Config::IniFileSetting.new(name, self, nil)
|
28
|
-
end
|
29
|
-
|
30
|
-
yield name, new_setting
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Serializes object data into an INI file string.
|
35
|
-
#
|
36
|
-
# @see PDK::Config::Namespace.serialize_data
|
37
|
-
def serialize_data(data)
|
38
|
-
default_lines = ''
|
39
|
-
lines = ''
|
40
|
-
data.each do |name, value|
|
41
|
-
next if value.nil?
|
42
|
-
if value.is_a?(Hash)
|
43
|
-
# Hashes are an INI section
|
44
|
-
lines += "\n[#{name}]\n"
|
45
|
-
value.each do |child_name, child_value|
|
46
|
-
next if child_value.nil?
|
47
|
-
lines += "#{child_name} = #{munge_serialized_value(child_value)}\n"
|
48
|
-
end
|
49
|
-
else
|
50
|
-
default_lines += "#{name} = #{munge_serialized_value(value)}\n"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
default_lines + lines
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def munge_serialized_value(value)
|
60
|
-
value = value.to_s unless value.is_a?(String)
|
61
|
-
# Add enclosing quotes if there's a space in the value
|
62
|
-
value = '"' + value + '"' if value.include?(' ')
|
63
|
-
value
|
64
|
-
end
|
65
|
-
|
66
|
-
# Adapted from https://raw.githubusercontent.com/puppetlabs/puppet/6c257fc7827989c2af2901f974666f0f23611153/lib/puppet/settings/ini_file.rb
|
67
|
-
# rubocop:disable Style/RegexpLiteral
|
68
|
-
# rubocop:disable Style/PerlBackrefs
|
69
|
-
# rubocop:disable Style/RedundantSelf
|
70
|
-
# rubocop:disable Style/StringLiterals
|
71
|
-
class IniFileImpl
|
72
|
-
DEFAULT_SECTION_NAME = 'default_section_name'.freeze
|
73
|
-
|
74
|
-
def self.parse(config_fh)
|
75
|
-
config = new([DefaultSection.new])
|
76
|
-
config_fh.each_line do |line|
|
77
|
-
case line.chomp
|
78
|
-
when /^(\s*)\[([[:word:]]+)\](\s*)$/
|
79
|
-
config.append(SectionLine.new($1, $2, $3))
|
80
|
-
when /^(\s*)([[:word:]]+)(\s*=\s*)(.*?)(\s*)$/
|
81
|
-
config.append(SettingLine.new($1, $2, $3, $4, $5))
|
82
|
-
else
|
83
|
-
config.append(Line.new(line))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
config
|
88
|
-
end
|
89
|
-
|
90
|
-
def initialize(lines = [])
|
91
|
-
@lines = lines
|
92
|
-
end
|
93
|
-
|
94
|
-
def to_hash
|
95
|
-
result = {}
|
96
|
-
|
97
|
-
current_section_name = nil
|
98
|
-
@lines.each do |line|
|
99
|
-
if line.instance_of?(SectionLine)
|
100
|
-
current_section_name = line.name
|
101
|
-
result[current_section_name] = {}
|
102
|
-
elsif line.instance_of?(SettingLine)
|
103
|
-
if current_section_name.nil?
|
104
|
-
result[line.name] = munge_value(line.value)
|
105
|
-
else
|
106
|
-
result[current_section_name][line.name] = munge_value(line.value)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
result
|
112
|
-
end
|
113
|
-
|
114
|
-
def munge_value(value)
|
115
|
-
value = value.to_s unless value.is_a?(String)
|
116
|
-
# Strip enclosing quotes
|
117
|
-
value = value.slice(1...-1) if value.start_with?('"') && value.end_with?('"')
|
118
|
-
value
|
119
|
-
end
|
120
|
-
|
121
|
-
def append(line)
|
122
|
-
line.previous = @lines.last
|
123
|
-
@lines << line
|
124
|
-
end
|
125
|
-
|
126
|
-
module LineNumber
|
127
|
-
attr_accessor :previous
|
128
|
-
|
129
|
-
def line_number
|
130
|
-
line = 0
|
131
|
-
previous_line = previous
|
132
|
-
while previous_line
|
133
|
-
line += 1
|
134
|
-
previous_line = previous_line.previous
|
135
|
-
end
|
136
|
-
line
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
Line = Struct.new(:text) do
|
141
|
-
include LineNumber
|
142
|
-
|
143
|
-
def to_s
|
144
|
-
text
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
SettingLine = Struct.new(:prefix, :name, :infix, :value, :suffix) do
|
149
|
-
include LineNumber
|
150
|
-
|
151
|
-
def to_s
|
152
|
-
"#{prefix}#{name}#{infix}#{value}#{suffix}"
|
153
|
-
end
|
154
|
-
|
155
|
-
def ==(other)
|
156
|
-
super(other) && self.line_number == other.line_number
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
SectionLine = Struct.new(:prefix, :name, :suffix) do
|
161
|
-
include LineNumber
|
162
|
-
|
163
|
-
def to_s
|
164
|
-
"#{prefix}[#{name}]#{suffix}"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
class DefaultSection < SectionLine
|
169
|
-
attr_accessor :write_sectionline
|
170
|
-
|
171
|
-
def initialize
|
172
|
-
@write_sectionline = false
|
173
|
-
super("", DEFAULT_SECTION_NAME, "")
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
# rubocop:enable Style/StringLiterals
|
178
|
-
# rubocop:enable Style/RedundantSelf
|
179
|
-
# rubocop:enable Style/PerlBackrefs
|
180
|
-
# rubocop:enable Style/RegexpLiteral
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
class Config
|
5
|
+
# Represents a configuration file using the INI file format
|
6
|
+
class IniFile < Namespace
|
7
|
+
# Ini Files have very strict valdiation rules which are set in the IniFileSetting class
|
8
|
+
# @see PDK::Config::Namespace.default_setting_class
|
9
|
+
def default_setting_class
|
10
|
+
PDK::Config::IniFileSetting
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parses an IniFile document.
|
14
|
+
#
|
15
|
+
# @see PDK::Config::Namespace.parse_file
|
16
|
+
def parse_file(filename)
|
17
|
+
raise unless block_given?
|
18
|
+
data = load_data(filename)
|
19
|
+
return if data.nil? || data.empty?
|
20
|
+
|
21
|
+
ini_file = IniFileImpl.parse(data)
|
22
|
+
ini_file.to_hash.each do |name, value|
|
23
|
+
begin
|
24
|
+
new_setting = PDK::Config::IniFileSetting.new(name, self, value)
|
25
|
+
rescue StandardError
|
26
|
+
# We just ignore invalid initial settings
|
27
|
+
new_setting = PDK::Config::IniFileSetting.new(name, self, nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
yield name, new_setting
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Serializes object data into an INI file string.
|
35
|
+
#
|
36
|
+
# @see PDK::Config::Namespace.serialize_data
|
37
|
+
def serialize_data(data)
|
38
|
+
default_lines = ''
|
39
|
+
lines = ''
|
40
|
+
data.each do |name, value|
|
41
|
+
next if value.nil?
|
42
|
+
if value.is_a?(Hash)
|
43
|
+
# Hashes are an INI section
|
44
|
+
lines += "\n[#{name}]\n"
|
45
|
+
value.each do |child_name, child_value|
|
46
|
+
next if child_value.nil?
|
47
|
+
lines += "#{child_name} = #{munge_serialized_value(child_value)}\n"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
default_lines += "#{name} = #{munge_serialized_value(value)}\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
default_lines + lines
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def munge_serialized_value(value)
|
60
|
+
value = value.to_s unless value.is_a?(String)
|
61
|
+
# Add enclosing quotes if there's a space in the value
|
62
|
+
value = '"' + value + '"' if value.include?(' ')
|
63
|
+
value
|
64
|
+
end
|
65
|
+
|
66
|
+
# Adapted from https://raw.githubusercontent.com/puppetlabs/puppet/6c257fc7827989c2af2901f974666f0f23611153/lib/puppet/settings/ini_file.rb
|
67
|
+
# rubocop:disable Style/RegexpLiteral
|
68
|
+
# rubocop:disable Style/PerlBackrefs
|
69
|
+
# rubocop:disable Style/RedundantSelf
|
70
|
+
# rubocop:disable Style/StringLiterals
|
71
|
+
class IniFileImpl
|
72
|
+
DEFAULT_SECTION_NAME = 'default_section_name'.freeze
|
73
|
+
|
74
|
+
def self.parse(config_fh)
|
75
|
+
config = new([DefaultSection.new])
|
76
|
+
config_fh.each_line do |line|
|
77
|
+
case line.chomp
|
78
|
+
when /^(\s*)\[([[:word:]]+)\](\s*)$/
|
79
|
+
config.append(SectionLine.new($1, $2, $3))
|
80
|
+
when /^(\s*)([[:word:]]+)(\s*=\s*)(.*?)(\s*)$/
|
81
|
+
config.append(SettingLine.new($1, $2, $3, $4, $5))
|
82
|
+
else
|
83
|
+
config.append(Line.new(line))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
config
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize(lines = [])
|
91
|
+
@lines = lines
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_hash
|
95
|
+
result = {}
|
96
|
+
|
97
|
+
current_section_name = nil
|
98
|
+
@lines.each do |line|
|
99
|
+
if line.instance_of?(SectionLine)
|
100
|
+
current_section_name = line.name
|
101
|
+
result[current_section_name] = {}
|
102
|
+
elsif line.instance_of?(SettingLine)
|
103
|
+
if current_section_name.nil?
|
104
|
+
result[line.name] = munge_value(line.value)
|
105
|
+
else
|
106
|
+
result[current_section_name][line.name] = munge_value(line.value)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
result
|
112
|
+
end
|
113
|
+
|
114
|
+
def munge_value(value)
|
115
|
+
value = value.to_s unless value.is_a?(String)
|
116
|
+
# Strip enclosing quotes
|
117
|
+
value = value.slice(1...-1) if value.start_with?('"') && value.end_with?('"')
|
118
|
+
value
|
119
|
+
end
|
120
|
+
|
121
|
+
def append(line)
|
122
|
+
line.previous = @lines.last
|
123
|
+
@lines << line
|
124
|
+
end
|
125
|
+
|
126
|
+
module LineNumber
|
127
|
+
attr_accessor :previous
|
128
|
+
|
129
|
+
def line_number
|
130
|
+
line = 0
|
131
|
+
previous_line = previous
|
132
|
+
while previous_line
|
133
|
+
line += 1
|
134
|
+
previous_line = previous_line.previous
|
135
|
+
end
|
136
|
+
line
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Line = Struct.new(:text) do
|
141
|
+
include LineNumber
|
142
|
+
|
143
|
+
def to_s
|
144
|
+
text
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
SettingLine = Struct.new(:prefix, :name, :infix, :value, :suffix) do
|
149
|
+
include LineNumber
|
150
|
+
|
151
|
+
def to_s
|
152
|
+
"#{prefix}#{name}#{infix}#{value}#{suffix}"
|
153
|
+
end
|
154
|
+
|
155
|
+
def ==(other)
|
156
|
+
super(other) && self.line_number == other.line_number
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
SectionLine = Struct.new(:prefix, :name, :suffix) do
|
161
|
+
include LineNumber
|
162
|
+
|
163
|
+
def to_s
|
164
|
+
"#{prefix}[#{name}]#{suffix}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class DefaultSection < SectionLine
|
169
|
+
attr_accessor :write_sectionline
|
170
|
+
|
171
|
+
def initialize
|
172
|
+
@write_sectionline = false
|
173
|
+
super("", DEFAULT_SECTION_NAME, "")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
# rubocop:enable Style/StringLiterals
|
178
|
+
# rubocop:enable Style/RedundantSelf
|
179
|
+
# rubocop:enable Style/PerlBackrefs
|
180
|
+
# rubocop:enable Style/RegexpLiteral
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
class Config
|
5
|
-
class IniFileSetting < PDK::Config::Setting
|
6
|
-
# Initialises the PDK::Config::JSONSchemaSetting object.
|
7
|
-
#
|
8
|
-
# @see PDK::Config::Setting.initialize
|
9
|
-
def initialize(_name, namespace, initial_value = nil)
|
10
|
-
raise 'The IniFileSetting object can only be created within the IniFile Namespace' unless namespace.is_a?(PDK::Config::IniFile)
|
11
|
-
super
|
12
|
-
validate!(initial_value) unless initial_value.nil?
|
13
|
-
end
|
14
|
-
|
15
|
-
# Verifies that the new setting value is valid in an Ini File
|
16
|
-
#
|
17
|
-
# @see PDK::Config::Setting.validate!
|
18
|
-
def validate!(value)
|
19
|
-
# We're very restrictive here. Realistically Ini files only have string types
|
20
|
-
return if value.nil? || value.is_a?(String) || value.is_a?(Integer)
|
21
|
-
# The only other valid-ish type is a Hash
|
22
|
-
unless value.is_a?(Hash)
|
23
|
-
raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
|
24
|
-
key: qualified_name,
|
25
|
-
class: value.class,
|
26
|
-
}
|
27
|
-
end
|
28
|
-
# Any hashes can only have a single String/Integer value
|
29
|
-
value.each do |child_name, child_value|
|
30
|
-
next if child_value.nil? || child_value.is_a?(String) || child_value.is_a?(Integer)
|
31
|
-
raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
|
32
|
-
key: qualified_name + '.' + child_name,
|
33
|
-
class: child_value.class,
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
class Config
|
5
|
+
class IniFileSetting < PDK::Config::Setting
|
6
|
+
# Initialises the PDK::Config::JSONSchemaSetting object.
|
7
|
+
#
|
8
|
+
# @see PDK::Config::Setting.initialize
|
9
|
+
def initialize(_name, namespace, initial_value = nil)
|
10
|
+
raise 'The IniFileSetting object can only be created within the IniFile Namespace' unless namespace.is_a?(PDK::Config::IniFile)
|
11
|
+
super
|
12
|
+
validate!(initial_value) unless initial_value.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
# Verifies that the new setting value is valid in an Ini File
|
16
|
+
#
|
17
|
+
# @see PDK::Config::Setting.validate!
|
18
|
+
def validate!(value)
|
19
|
+
# We're very restrictive here. Realistically Ini files only have string types
|
20
|
+
return if value.nil? || value.is_a?(String) || value.is_a?(Integer)
|
21
|
+
# The only other valid-ish type is a Hash
|
22
|
+
unless value.is_a?(Hash)
|
23
|
+
raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
|
24
|
+
key: qualified_name,
|
25
|
+
class: value.class,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
# Any hashes can only have a single String/Integer value
|
29
|
+
value.each do |child_name, child_value|
|
30
|
+
next if child_value.nil? || child_value.is_a?(String) || child_value.is_a?(Integer)
|
31
|
+
raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
|
32
|
+
key: qualified_name + '.' + child_name,
|
33
|
+
class: child_value.class,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/pdk/config/json.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
class Config
|
5
|
-
class JSON < Namespace
|
6
|
-
# Parses a JSON document.
|
7
|
-
#
|
8
|
-
# @see PDK::Config::Namespace.parse_file
|
9
|
-
def parse_file(filename)
|
10
|
-
raise unless block_given?
|
11
|
-
data = load_data(filename)
|
12
|
-
return if data.nil? || data.empty?
|
13
|
-
|
14
|
-
require 'json'
|
15
|
-
|
16
|
-
data = ::JSON.parse(data)
|
17
|
-
return if data.nil? || data.empty?
|
18
|
-
|
19
|
-
data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) }
|
20
|
-
rescue ::JSON::ParserError => e
|
21
|
-
raise PDK::Config::LoadError, e.message
|
22
|
-
end
|
23
|
-
|
24
|
-
# Serializes object data into a JSON string.
|
25
|
-
#
|
26
|
-
# @see PDK::Config::Namespace.serialize_data
|
27
|
-
def serialize_data(data)
|
28
|
-
require 'json'
|
29
|
-
|
30
|
-
::JSON.pretty_generate(data)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
class Config
|
5
|
+
class JSON < Namespace
|
6
|
+
# Parses a JSON document.
|
7
|
+
#
|
8
|
+
# @see PDK::Config::Namespace.parse_file
|
9
|
+
def parse_file(filename)
|
10
|
+
raise unless block_given?
|
11
|
+
data = load_data(filename)
|
12
|
+
return if data.nil? || data.empty?
|
13
|
+
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
data = ::JSON.parse(data)
|
17
|
+
return if data.nil? || data.empty?
|
18
|
+
|
19
|
+
data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) }
|
20
|
+
rescue ::JSON::ParserError => e
|
21
|
+
raise PDK::Config::LoadError, e.message
|
22
|
+
end
|
23
|
+
|
24
|
+
# Serializes object data into a JSON string.
|
25
|
+
#
|
26
|
+
# @see PDK::Config::Namespace.serialize_data
|
27
|
+
def serialize_data(data)
|
28
|
+
require 'json'
|
29
|
+
|
30
|
+
::JSON.pretty_generate(data)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|