pdk 2.4.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +803 -1329
  3. data/LICENSE +201 -201
  4. data/README.md +165 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -278
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2111 -2094
  153. metadata +3 -3
@@ -1,135 +1,135 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- class Config
5
- # A class for describing the setting of a {PDK::Config} setting.
6
- #
7
- # Generally, this is never instantiated manually, but is instead
8
- # instantiated by passing a block to {PDK::Config::Namespace#setting}.
9
- #
10
- # @example
11
- #
12
- # PDK::Config::Namespace.new('analytics') do
13
- # setting :disabled do
14
- # validate PDK::Config::Validator.boolean
15
- # default_to { false }
16
- # end
17
- # end
18
- class Setting
19
- attr_reader :namespace
20
-
21
- # It is possible to have multiple setting definitions for the same setting; for example, defining a default value with a lambda, but the
22
- # the validation is within a JSON schema document. These are expressed as two settings objects, and uses a single linked list to join them
23
- # together:
24
- #
25
- # (PDK::Config::JSONSchemaSetting) --previous_setting--> (PDK::Config::Setting)
26
- #
27
- # So in the example above, calling `default` the on the first object in the list will:
28
- # 1. Look at `default` on PDK::Config::JSONSchemaSetting
29
- # 2. If a default could not be found then it calls `default` on previous_setting
30
- # 3. If a default could not be found then it calls `default` on previous_setting.previous_setting
31
- # 4. and so on down the linked list (chain) of settings
32
- attr_writer :previous_setting
33
-
34
- # Initialises an empty setting definition.
35
- #
36
- # @param name [String,Symbol] the name of the setting.
37
- # @param namespace [PDK::Config::Namespace] The namespace this setting belongs to
38
- def initialize(name, namespace, initial_value = nil)
39
- @name = name.to_s
40
- @validators = []
41
- @namespace = namespace
42
- @value = initial_value
43
- end
44
-
45
- def qualified_name
46
- [namespace.name, @name].join('.')
47
- end
48
-
49
- def value
50
- # Duplicate arrays and hashes so that they are isolated from changes being made
51
- PDK::Util.deep_duplicate(@value)
52
- end
53
-
54
- def value=(obj)
55
- validate!(obj)
56
- @value = obj
57
- end
58
-
59
- def to_s
60
- @value.to_s
61
- end
62
-
63
- # Assign a validator to the setting. Subclasses should not override this method.
64
- #
65
- # @param validator [Hash{Symbol => [Proc,String]}]
66
- # @option validator [Proc] :proc a lambda that takes the setting to be
67
- # validated as the argument and returns `true` if the setting is valid.
68
- # @option validator [String] :message a description of what the validator
69
- # is testing for, that is displayed to the user as part of the error
70
- # message for invalid settings.
71
- #
72
- # @raise [ArgumentError] if not passed a Hash.
73
- # @raise [ArgumentError] if the Hash doesn't have a `:proc` key that
74
- # contains a Proc.
75
- # @raise [ArgumentError] if the Hash doesn't have a `:message` key that
76
- # contains a String.
77
- #
78
- # @return [nil]
79
- def validate(validator)
80
- raise ArgumentError, _('`validator` must be a Hash') unless validator.is_a?(Hash)
81
- raise ArgumentError, _('the :proc key must contain a Proc') unless validator.key?(:proc) && validator[:proc].is_a?(Proc)
82
- raise ArgumentError, _('the :message key must contain a String') unless validator.key?(:message) && validator[:message].is_a?(String)
83
-
84
- @validators << validator
85
- end
86
-
87
- # Validate a setting against the assigned validators.
88
- #
89
- # @param setting [Object] the setting being validated.
90
- #
91
- # @raise [ArgumentError] if any of the assigned validators fail to
92
- # validate the setting.
93
- #
94
- # @return [nil]
95
- def validate!(value)
96
- @validators.each do |validator|
97
- next if validator[:proc].call(value)
98
-
99
- raise ArgumentError, _('%{key} %{message}') % {
100
- key: qualified_name,
101
- message: validator[:message],
102
- }
103
- end
104
- end
105
-
106
- # Assign a default value proc for the setting. Subclasses should not override this method.
107
- #
108
- # @param block [Proc] a block that is lazy evaluated when necessary in
109
- # order to determine the default setting.
110
- #
111
- # @return [nil]
112
- def default_to(&block)
113
- raise ArgumentError, _('must be passed a block') unless block_given?
114
- @default_to = block
115
- end
116
-
117
- # Evaluate the default setting.
118
- #
119
- # @return [Object,nil] the result of evaluating the block given to
120
- # {#default_to}, or `nil` if the setting has no default.
121
- def default
122
- return @default_to.call if default_block?
123
- # If there is a previous setting in the chain, use its default
124
- @previous_setting.nil? ? nil : @previous_setting.default
125
- end
126
-
127
- private
128
-
129
- # @return [Boolean] true if the setting has a default setting block. Subclasses should not override this method.
130
- def default_block?
131
- !@default_to.nil?
132
- end
133
- end
134
- end
135
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ class Config
5
+ # A class for describing the setting of a {PDK::Config} setting.
6
+ #
7
+ # Generally, this is never instantiated manually, but is instead
8
+ # instantiated by passing a block to {PDK::Config::Namespace#setting}.
9
+ #
10
+ # @example
11
+ #
12
+ # PDK::Config::Namespace.new('analytics') do
13
+ # setting :disabled do
14
+ # validate PDK::Config::Validator.boolean
15
+ # default_to { false }
16
+ # end
17
+ # end
18
+ class Setting
19
+ attr_reader :namespace
20
+
21
+ # It is possible to have multiple setting definitions for the same setting; for example, defining a default value with a lambda, but the
22
+ # the validation is within a JSON schema document. These are expressed as two settings objects, and uses a single linked list to join them
23
+ # together:
24
+ #
25
+ # (PDK::Config::JSONSchemaSetting) --previous_setting--> (PDK::Config::Setting)
26
+ #
27
+ # So in the example above, calling `default` the on the first object in the list will:
28
+ # 1. Look at `default` on PDK::Config::JSONSchemaSetting
29
+ # 2. If a default could not be found then it calls `default` on previous_setting
30
+ # 3. If a default could not be found then it calls `default` on previous_setting.previous_setting
31
+ # 4. and so on down the linked list (chain) of settings
32
+ attr_writer :previous_setting
33
+
34
+ # Initialises an empty setting definition.
35
+ #
36
+ # @param name [String,Symbol] the name of the setting.
37
+ # @param namespace [PDK::Config::Namespace] The namespace this setting belongs to
38
+ def initialize(name, namespace, initial_value = nil)
39
+ @name = name.to_s
40
+ @validators = []
41
+ @namespace = namespace
42
+ @value = initial_value
43
+ end
44
+
45
+ def qualified_name
46
+ [namespace.name, @name].join('.')
47
+ end
48
+
49
+ def value
50
+ # Duplicate arrays and hashes so that they are isolated from changes being made
51
+ PDK::Util.deep_duplicate(@value)
52
+ end
53
+
54
+ def value=(obj)
55
+ validate!(obj)
56
+ @value = obj
57
+ end
58
+
59
+ def to_s
60
+ @value.to_s
61
+ end
62
+
63
+ # Assign a validator to the setting. Subclasses should not override this method.
64
+ #
65
+ # @param validator [Hash{Symbol => [Proc,String]}]
66
+ # @option validator [Proc] :proc a lambda that takes the setting to be
67
+ # validated as the argument and returns `true` if the setting is valid.
68
+ # @option validator [String] :message a description of what the validator
69
+ # is testing for, that is displayed to the user as part of the error
70
+ # message for invalid settings.
71
+ #
72
+ # @raise [ArgumentError] if not passed a Hash.
73
+ # @raise [ArgumentError] if the Hash doesn't have a `:proc` key that
74
+ # contains a Proc.
75
+ # @raise [ArgumentError] if the Hash doesn't have a `:message` key that
76
+ # contains a String.
77
+ #
78
+ # @return [nil]
79
+ def validate(validator)
80
+ raise ArgumentError, _('`validator` must be a Hash') unless validator.is_a?(Hash)
81
+ raise ArgumentError, _('the :proc key must contain a Proc') unless validator.key?(:proc) && validator[:proc].is_a?(Proc)
82
+ raise ArgumentError, _('the :message key must contain a String') unless validator.key?(:message) && validator[:message].is_a?(String)
83
+
84
+ @validators << validator
85
+ end
86
+
87
+ # Validate a setting against the assigned validators.
88
+ #
89
+ # @param setting [Object] the setting being validated.
90
+ #
91
+ # @raise [ArgumentError] if any of the assigned validators fail to
92
+ # validate the setting.
93
+ #
94
+ # @return [nil]
95
+ def validate!(value)
96
+ @validators.each do |validator|
97
+ next if validator[:proc].call(value)
98
+
99
+ raise ArgumentError, _('%{key} %{message}') % {
100
+ key: qualified_name,
101
+ message: validator[:message],
102
+ }
103
+ end
104
+ end
105
+
106
+ # Assign a default value proc for the setting. Subclasses should not override this method.
107
+ #
108
+ # @param block [Proc] a block that is lazy evaluated when necessary in
109
+ # order to determine the default setting.
110
+ #
111
+ # @return [nil]
112
+ def default_to(&block)
113
+ raise ArgumentError, _('must be passed a block') unless block_given?
114
+ @default_to = block
115
+ end
116
+
117
+ # Evaluate the default setting.
118
+ #
119
+ # @return [Object,nil] the result of evaluating the block given to
120
+ # {#default_to}, or `nil` if the setting has no default.
121
+ def default
122
+ return @default_to.call if default_block?
123
+ # If there is a previous setting in the chain, use its default
124
+ @previous_setting.nil? ? nil : @previous_setting.default
125
+ end
126
+
127
+ private
128
+
129
+ # @return [Boolean] true if the setting has a default setting block. Subclasses should not override this method.
130
+ def default_block?
131
+ !@default_to.nil?
132
+ end
133
+ end
134
+ end
135
+ end
@@ -1,31 +1,31 @@
1
- module PDK
2
- class Config
3
- # A collection of predefined validators for use with {PDK::Config::Value}.
4
- #
5
- # @example
6
- # value :enabled do
7
- # validate PDK::Config::Validator.boolean
8
- # end
9
- module Validator
10
- # @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
11
- # validator that ensures that the value is either a TrueClass or
12
- # FalseClass.
13
- def self.boolean
14
- {
15
- proc: ->(value) { [true, false].include?(value) },
16
- message: _('must be a boolean: true or false'),
17
- }
18
- end
19
-
20
- # @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
21
- # validator that ensures that the value is a String that matches the
22
- # regex for a version 4 UUID.
23
- def self.uuid
24
- {
25
- proc: ->(value) { value.match(%r{\A\h{8}(?:-\h{4}){3}-\h{12}\z}) },
26
- message: _('must be a version 4 UUID'),
27
- }
28
- end
29
- end
30
- end
31
- end
1
+ module PDK
2
+ class Config
3
+ # A collection of predefined validators for use with {PDK::Config::Value}.
4
+ #
5
+ # @example
6
+ # value :enabled do
7
+ # validate PDK::Config::Validator.boolean
8
+ # end
9
+ module Validator
10
+ # @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
11
+ # validator that ensures that the value is either a TrueClass or
12
+ # FalseClass.
13
+ def self.boolean
14
+ {
15
+ proc: ->(value) { [true, false].include?(value) },
16
+ message: _('must be a boolean: true or false'),
17
+ }
18
+ end
19
+
20
+ # @return [Hash{Symbol => [Proc,String]}] a {PDK::Config::Value}
21
+ # validator that ensures that the value is a String that matches the
22
+ # regex for a version 4 UUID.
23
+ def self.uuid
24
+ {
25
+ proc: ->(value) { value.match(%r{\A\h{8}(?:-\h{4}){3}-\h{12}\z}) },
26
+ message: _('must be a version 4 UUID'),
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,46 +1,46 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- class Config
5
- # Parses a YAML document.
6
- #
7
- # @see PDK::Config::Namespace.parse_file
8
- class YAML < Namespace
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 'yaml'
15
-
16
- data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
17
- ::YAML.safe_load(data, permitted_classes: [Symbol], permitted_symbols: [], aliases: true)
18
- else
19
- ::YAML.safe_load(data, [Symbol], [], true)
20
- end
21
- return if data.nil?
22
-
23
- data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) }
24
- rescue Psych::SyntaxError => e
25
- raise PDK::Config::LoadError, _('Syntax error when loading %{file}: %{error}') % {
26
- file: filename,
27
- error: "#{e.problem} #{e.context}",
28
- }
29
- rescue Psych::DisallowedClass => e
30
- raise PDK::Config::LoadError, _('Unsupported class in %{file}: %{error}') % {
31
- file: filename,
32
- error: e.message,
33
- }
34
- end
35
-
36
- # Serializes object data into a YAML string.
37
- #
38
- # @see PDK::Config::Namespace.serialize_data
39
- def serialize_data(data)
40
- require 'yaml'
41
-
42
- ::YAML.dump(data)
43
- end
44
- end
45
- end
46
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ class Config
5
+ # Parses a YAML document.
6
+ #
7
+ # @see PDK::Config::Namespace.parse_file
8
+ class YAML < Namespace
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 'yaml'
15
+
16
+ data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
17
+ ::YAML.safe_load(data, permitted_classes: [Symbol], permitted_symbols: [], aliases: true)
18
+ else
19
+ ::YAML.safe_load(data, [Symbol], [], true)
20
+ end
21
+ return if data.nil?
22
+
23
+ data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) }
24
+ rescue Psych::SyntaxError => e
25
+ raise PDK::Config::LoadError, _('Syntax error when loading %{file}: %{error}') % {
26
+ file: filename,
27
+ error: "#{e.problem} #{e.context}",
28
+ }
29
+ rescue Psych::DisallowedClass => e
30
+ raise PDK::Config::LoadError, _('Unsupported class in %{file}: %{error}') % {
31
+ file: filename,
32
+ error: e.message,
33
+ }
34
+ end
35
+
36
+ # Serializes object data into a YAML string.
37
+ #
38
+ # @see PDK::Config::Namespace.serialize_data
39
+ def serialize_data(data)
40
+ require 'yaml'
41
+
42
+ ::YAML.dump(data)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,59 +1,59 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- class Config
5
- # Parses a YAML document with a JSON schema.
6
- #
7
- # @see PDK::Config::Namespace.parse_file
8
- class YAMLWithSchema < JSONSchemaNamespace
9
- def parse_file(filename)
10
- raise unless block_given?
11
- data = load_data(filename)
12
- data = '' if data.nil?
13
- require 'yaml'
14
- require 'json-schema'
15
-
16
- @raw_data = ::YAML.safe_load(data, [Symbol], [], true)
17
- @raw_data = {} if @raw_data.nil?
18
-
19
- begin
20
- # Ensure the parsed document is actually valid
21
- validate_document!(@raw_data)
22
- rescue ::JSON::Schema::ValidationError => e
23
- raise PDK::Config::LoadError, _('The configuration file %{filename} is not valid: %{message}') % {
24
- filename: filename,
25
- message: e.message,
26
- }
27
- end
28
-
29
- require 'pdk/config/json_schema_setting'
30
-
31
- schema_property_names.each do |key|
32
- yield key, PDK::Config::JSONSchemaSetting.new(key, self, @raw_data[key])
33
- end
34
-
35
- # Remove all of the "known" settings from the schema and
36
- # we're left with the settings that we don't manage.
37
- self.unmanaged_settings = @raw_data.reject { |k, _| schema_property_names.include?(k) }
38
- rescue Psych::SyntaxError => e
39
- raise PDK::Config::LoadError, _('Syntax error when loading %{file}: %{error}') % {
40
- file: filename,
41
- error: "#{e.problem} #{e.context}",
42
- }
43
- rescue Psych::DisallowedClass => e
44
- raise PDK::Config::LoadError, _('Unsupported class in %{file}: %{error}') % {
45
- file: filename,
46
- error: e.message,
47
- }
48
- end
49
-
50
- # Serializes object data into a YAML string.
51
- #
52
- # @see PDK::Config::Namespace.serialize_data
53
- def serialize_data(data)
54
- require 'yaml'
55
- ::YAML.dump(data)
56
- end
57
- end
58
- end
59
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ class Config
5
+ # Parses a YAML document with a JSON schema.
6
+ #
7
+ # @see PDK::Config::Namespace.parse_file
8
+ class YAMLWithSchema < JSONSchemaNamespace
9
+ def parse_file(filename)
10
+ raise unless block_given?
11
+ data = load_data(filename)
12
+ data = '' if data.nil?
13
+ require 'yaml'
14
+ require 'json-schema'
15
+
16
+ @raw_data = ::YAML.safe_load(data, [Symbol], [], true)
17
+ @raw_data = {} if @raw_data.nil?
18
+
19
+ begin
20
+ # Ensure the parsed document is actually valid
21
+ validate_document!(@raw_data)
22
+ rescue ::JSON::Schema::ValidationError => e
23
+ raise PDK::Config::LoadError, _('The configuration file %{filename} is not valid: %{message}') % {
24
+ filename: filename,
25
+ message: e.message,
26
+ }
27
+ end
28
+
29
+ require 'pdk/config/json_schema_setting'
30
+
31
+ schema_property_names.each do |key|
32
+ yield key, PDK::Config::JSONSchemaSetting.new(key, self, @raw_data[key])
33
+ end
34
+
35
+ # Remove all of the "known" settings from the schema and
36
+ # we're left with the settings that we don't manage.
37
+ self.unmanaged_settings = @raw_data.reject { |k, _| schema_property_names.include?(k) }
38
+ rescue Psych::SyntaxError => e
39
+ raise PDK::Config::LoadError, _('Syntax error when loading %{file}: %{error}') % {
40
+ file: filename,
41
+ error: "#{e.problem} #{e.context}",
42
+ }
43
+ rescue Psych::DisallowedClass => e
44
+ raise PDK::Config::LoadError, _('Unsupported class in %{file}: %{error}') % {
45
+ file: filename,
46
+ error: e.message,
47
+ }
48
+ end
49
+
50
+ # Serializes object data into a YAML string.
51
+ #
52
+ # @see PDK::Config::Namespace.serialize_data
53
+ def serialize_data(data)
54
+ require 'yaml'
55
+ ::YAML.dump(data)
56
+ end
57
+ end
58
+ end
59
+ end