Class: PDK::CLI::Util::OptionValidator
- Inherits:
-
Object
- Object
- PDK::CLI::Util::OptionValidator
- Defined in:
- lib/pdk/cli/util/option_validator.rb
Class Method Summary collapse
- .comma_separated_list?(list, _options = {}) ⇒ Boolean
- .enum(val, valid_entries, _options = {}) ⇒ Object
-
.valid_fact_name?(name) ⇒ Boolean
True if the fact name is valid.
-
.valid_module_name?(string) ⇒ Boolean
Validate the module name against the regular expression in the documentation: docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names.
-
.valid_namespace?(string) ⇒ Boolean
Validate a Puppet namespace against the regular expression in the documentation: docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types.
-
.valid_param_name?(string) ⇒ Boolean
Validate that a class/defined type parameter matches the regular expression in the documentation: docs.puppet.com/puppet/4.10/lang_reserved.html#parameters The parameter should also not be a reserved word or overload a metaparameter.
Class Method Details
.comma_separated_list?(list, _options = {}) ⇒ Boolean
7 8 9 |
# File 'lib/pdk/cli/util/option_validator.rb', line 7 def self.comma_separated_list?(list, = {}) /^[\w-]+(?:,[\w-]+)+$/.match?(list) end |
.enum(val, valid_entries, _options = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/pdk/cli/util/option_validator.rb', line 16 def self.enum(val, valid_entries, = {}) vals = val.is_a?(Array) ? val : [val] invalid_entries = vals.reject { |e| valid_entries.include?(e) } raise ArgumentError, format('Error: the following values are invalid: %{invalid_entries}', invalid_entries: invalid_entries) unless invalid_entries.empty? val end |
.valid_fact_name?(name) ⇒ Boolean
Returns true if the fact name is valid.
12 13 14 |
# File 'lib/pdk/cli/util/option_validator.rb', line 12 def self.valid_fact_name?(name) name.length > 1 end |
.valid_module_name?(string) ⇒ Boolean
Validate the module name against the regular expression in the documentation: docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names
27 28 29 |
# File 'lib/pdk/cli/util/option_validator.rb', line 27 def self.valid_module_name?(string) !(string =~ /\A[a-z][a-z0-9_]*\Z/).nil? end |
.valid_namespace?(string) ⇒ Boolean
Validate a Puppet namespace against the regular expression in the documentation: docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types
42 43 44 45 46 |
# File 'lib/pdk/cli/util/option_validator.rb', line 42 def self.valid_namespace?(string) return false if (string || '').split('::').last == 'init' !(string =~ /\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z/).nil? end |
.valid_param_name?(string) ⇒ Boolean
Validate that a class/defined type parameter matches the regular expression in the documentation: docs.puppet.com/puppet/4.10/lang_reserved.html#parameters The parameter should also not be a reserved word or overload a metaparameter.
56 57 58 59 60 61 62 |
# File 'lib/pdk/cli/util/option_validator.rb', line 56 def self.valid_param_name?(string) reserved_words = ['trusted', 'facts', 'server_facts', 'title', 'name'].freeze = ['alias', 'audit', 'before', 'loglevel', 'noop', 'notify', 'require', 'schedule', 'stage', 'subscribe', 'tag'].freeze return false if reserved_words.include?(string) || .include?(string) !(string =~ /\A[a-z][a-zA-Z0-9_]*\Z/).nil? end |