pdk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +3 -9
  4. data/exe/pdk +1 -1
  5. data/lib/pdk.rb +5 -4
  6. data/lib/pdk/cli.rb +62 -59
  7. data/lib/pdk/cli/errors.rb +1 -1
  8. data/lib/pdk/cli/exec.rb +154 -29
  9. data/lib/pdk/cli/input.rb +2 -2
  10. data/lib/pdk/cli/new.rb +12 -27
  11. data/lib/pdk/cli/new/class.rb +28 -41
  12. data/lib/pdk/cli/new/module.rb +30 -41
  13. data/lib/pdk/cli/test.rb +9 -20
  14. data/lib/pdk/cli/test/unit.rb +38 -0
  15. data/lib/pdk/cli/util/option_normalizer.rb +45 -19
  16. data/lib/pdk/cli/util/option_validator.rb +24 -20
  17. data/lib/pdk/cli/validate.rb +65 -65
  18. data/lib/pdk/generate.rb +5 -0
  19. data/lib/pdk/generators/module.rb +37 -33
  20. data/lib/pdk/generators/puppet_class.rb +1 -1
  21. data/lib/pdk/generators/puppet_object.rb +19 -20
  22. data/lib/pdk/logger.rb +1 -1
  23. data/lib/pdk/module/metadata.rb +35 -18
  24. data/lib/pdk/module/templatedir.rb +40 -33
  25. data/lib/pdk/report.rb +76 -19
  26. data/lib/pdk/report/event.rb +276 -0
  27. data/lib/pdk/template_file.rb +8 -6
  28. data/lib/pdk/tests/unit.rb +8 -3
  29. data/lib/pdk/util.rb +65 -0
  30. data/lib/pdk/util/bundler.rb +167 -0
  31. data/lib/pdk/util/version.rb +34 -0
  32. data/lib/pdk/validate.rb +3 -4
  33. data/lib/pdk/validators/base_validator.rb +60 -4
  34. data/lib/pdk/validators/metadata.rb +29 -0
  35. data/lib/pdk/validators/puppet/puppet_lint.rb +47 -0
  36. data/lib/pdk/validators/puppet/puppet_parser.rb +34 -0
  37. data/lib/pdk/validators/puppet_validator.rb +30 -0
  38. data/lib/pdk/validators/ruby/rubocop.rb +59 -0
  39. data/lib/pdk/validators/ruby_validator.rb +29 -0
  40. data/lib/pdk/version.rb +1 -1
  41. data/lib/puppet/util/windows.rb +14 -0
  42. data/lib/puppet/util/windows/api_types.rb +278 -0
  43. data/lib/puppet/util/windows/file.rb +488 -0
  44. data/lib/puppet/util/windows/string.rb +16 -0
  45. data/locales/de/pdk.po +263 -78
  46. data/locales/pdk.pot +224 -65
  47. metadata +60 -8
  48. data/lib/pdk/cli/tests/unit.rb +0 -52
  49. data/lib/pdk/validators/puppet_lint.rb +0 -17
  50. data/lib/pdk/validators/puppet_parser.rb +0 -17
  51. data/lib/pdk/validators/ruby_lint.rb +0 -17
@@ -1,81 +1,81 @@
1
- require 'cri'
2
- require 'pdk/cli/util/option_validator'
3
- require 'pdk/report'
1
+ require 'pdk/util/bundler'
4
2
 
5
- require 'pdk/validate'
3
+ module PDK::CLI
4
+ @validate_cmd = @base_cmd.define_command do
5
+ name 'validate'
6
+ usage _('validate [options]')
7
+ summary _('Run static analysis tests.')
8
+ description _('Run metadata, puppet, or ruby validation.')
6
9
 
7
- module PDK
8
- module CLI
9
- class Validate
10
- include PDK::CLI::Util
10
+ flag nil, :list, _('list all available validators')
11
11
 
12
- def self.command
13
- @validate ||= Cri::Command.define do
14
- name 'validate'
15
- usage _("validate [options]")
16
- summary _("Run static analysis tests.")
17
- description _("Run metadata-json-lint, puppet parser validate, puppet-lint, or rubocop.")
12
+ run do |opts, args, _cmd|
13
+ validator_names = PDK::Validate.validators.map { |v| v.name }
14
+ validators = PDK::Validate.validators
15
+ targets = []
18
16
 
19
- flag nil, :list, _("list all available validators")
17
+ if opts[:list]
18
+ PDK.logger.info(_('Available validators: %{validator_names}') % { validator_names: validator_names.join(', ') })
19
+ exit 0
20
+ end
20
21
 
21
- run do |opts, args, cmd|
22
- validator_names = PDK::Validate.validators.map { |v| v.name }
23
- validators = PDK::Validate.validators
24
- targets = []
25
- reports = nil
22
+ if args[0]
23
+ # This may be a single validator, a list of validators, or a target.
24
+ if Util::OptionValidator.comma_separated_list?(args[0])
25
+ # This is a comma separated list. Treat each item as a validator.
26
26
 
27
- if opts[:list]
28
- puts _("Available validators: %{validator_names}") % {validator_names: validator_names.join(', ')}
29
- exit 0
30
- end
27
+ vals = Util::OptionNormalizer.comma_separated_list_to_array(args[0])
28
+ validators = PDK::Validate.validators.select { |v| vals.include?(v.name) }
31
29
 
32
- if args[0]
33
- # This may be a single validator, a list of validators, or a target.
34
- if OptionValidator.is_comma_separated_list?(args[0])
35
- # This is a comma separated list. Treat each item as a validator.
30
+ invalid = vals.reject { |v| validator_names.include?(v) }
31
+ invalid.each do |v|
32
+ PDK.logger.warn(_("Unknown validator '%{v}'. Available validators: %{validators}") % { v: v, validators: validator_names.join(', ') })
33
+ end
34
+ else
35
+ # This is a single item. Check if it's a known validator, or otherwise treat it as a target.
36
+ val = PDK::Validate.validators.find { |v| args[0] == v.name }
37
+ if val
38
+ validators = [val]
39
+ else
40
+ targets = [args[0]]
41
+ # We now know that no validators were passed, so let the user know we're using all of them by default.
42
+ PDK.logger.info(_('Running all available validators...'))
43
+ end
44
+ end
45
+ else
46
+ PDK.logger.info(_('Running all available validators...'))
47
+ end
36
48
 
37
- vals = OptionNormalizer.comma_separated_list_to_array(args[0])
38
- validators = PDK::Validate.validators.find_all { |v| vals.include?(v.name) }
49
+ # Subsequent arguments are targets.
50
+ targets.concat(args[1..-1]) if args.length > 1
39
51
 
40
- invalid = vals.find_all { |v| !validator_names.include?(v) }
41
- invalid.each do |v|
42
- PDK.logger.warn(_("Unknown validator '%{v}'. Available validators: %{validators}") % {v: v, validators: validator_names.join(', ')})
43
- end
44
- else
45
- # This is a single item. Check if it's a known validator, or otherwise treat it as a target.
46
- val = PDK::Validate.validators.find { |v| args[0] == v.name }
47
- if val
48
- validators = [val]
49
- else
50
- targets = [args[0]]
51
- # We now know that no validators were passed, so let the user know we're using all of them by default.
52
- PDK.logger.info(_("Running all available validators..."))
53
- end
54
- end
55
- else
56
- PDK.logger.info(_("Running all available validators..."))
57
- end
52
+ report = PDK::Report.new
53
+ report_formats = if opts[:format]
54
+ PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
55
+ else
56
+ [{
57
+ method: PDK::Report.default_format,
58
+ target: PDK::Report.default_target,
59
+ }]
60
+ end
58
61
 
59
- # Subsequent arguments are targets.
60
- targets.concat(args[1..-1]) if args.length > 1
62
+ options = targets.empty? ? {} : { targets: targets }
61
63
 
62
- # Note: Reporting may be delegated to the validation tool itself.
63
- if opts[:format]
64
- reports = OptionNormalizer.report_formats(opts.fetch(:format))
65
- end
64
+ exit_code = 0
66
65
 
67
- options = targets.empty? ? {} : { :targets => targets }
68
- validators.each do |validator|
69
- result = validator.invoke(options)
70
- if reports
71
- reports.each do |r|
72
- r.write(result)
73
- end
74
- end
75
- end
76
- end
77
- end
66
+ # Ensure that the bundle is installed and tools are available before running any validations.
67
+ PDK::Util::Bundler.ensure_bundle!
68
+
69
+ validators.each do |validator|
70
+ exit_code = validator.invoke(report, options)
71
+ break if exit_code != 0
78
72
  end
73
+
74
+ report_formats.each do |format|
75
+ report.send(format[:method], format[:target])
76
+ end
77
+
78
+ exit exit_code
79
79
  end
80
80
  end
81
81
  end
data/lib/pdk/generate.rb CHANGED
@@ -1,3 +1,8 @@
1
+ require 'pdk/generators/module'
2
+ require 'pdk/generators/puppet_class'
3
+ require 'pdk/module/metadata'
4
+ require 'pdk/module/templatedir'
5
+
1
6
  module PDK
2
7
  module Generate; end
3
8
  end
@@ -9,31 +9,35 @@ require 'pdk/module/templatedir'
9
9
  require 'pdk/cli/exec'
10
10
  require 'pdk/cli/input'
11
11
  require 'pdk/util'
12
+ require 'pdk/util/version'
12
13
 
13
14
  module PDK
14
15
  module Generate
15
16
  class Module
16
- DEFAULT_TEMPLATE = 'https://github.com/puppetlabs/pdk-module-template'
17
+ DEFAULT_TEMPLATE = 'https://github.com/puppetlabs/pdk-module-template'.freeze
17
18
 
18
- def self.invoke(opts={})
19
+ def self.invoke(opts = {})
19
20
  defaults = {
21
+ 'name' => "#{Etc.getlogin}-#{opts[:name]}",
20
22
  'version' => '0.1.0',
21
23
  'dependencies' => [
22
- { 'name' => 'puppetlabs-stdlib', 'version_requirement' => '>= 1.0.0' }
23
- ]
24
+ { 'name' => 'puppetlabs-stdlib', 'version_requirement' => '>= 4.13.1 < 5.0.0' },
25
+ ],
24
26
  }
25
27
 
26
- defaults['license'] = opts[:license] if opts.has_key? :license
28
+ defaults['license'] = opts[:license] if opts.key? :license
27
29
  target_dir = File.expand_path(opts[:target_dir])
28
30
 
29
- if File.exists?(target_dir)
30
- raise PDK::CLI::FatalError, _("The destination directory '%{dir}' already exists") % {:dir => target_dir}
31
+ if File.exist?(target_dir)
32
+ raise PDK::CLI::FatalError, _("The destination directory '%{dir}' already exists") % { dir: target_dir }
31
33
  end
32
34
 
33
35
  metadata = PDK::Module::Metadata.new(defaults)
34
36
 
35
37
  module_interview(metadata, opts) unless opts[:'skip-interview'] # @todo Build way to get info by answers file
36
38
 
39
+ metadata.update!('pdk-version' => PDK::Util::Version.version_string)
40
+
37
41
  temp_target_dir = PDK::Util.make_tmpdir_name('pdk-module-target')
38
42
 
39
43
  prepare_module_directory(temp_target_dir)
@@ -67,60 +71,60 @@ module PDK
67
71
  begin
68
72
  FileUtils.mkdir_p(dir)
69
73
  rescue SystemCallError
70
- raise PDK::CLI::FatalError, _("Unable to create directory '%{dir}'") % {:dir => dir}
74
+ raise PDK::CLI::FatalError, _("Unable to create directory '%{dir}'") % { dir: dir }
71
75
  end
72
76
  end
73
77
  end
74
78
 
75
- def self.module_interview(metadata, opts={})
79
+ def self.module_interview(metadata, opts = {})
76
80
  puts _(
77
- "We need to create a metadata.json file for this module. Please answer the " +
78
- "following questions; if the question is not applicable to this module, feel free " +
79
- "to leave it blank."
81
+ 'We need to create a metadata.json file for this module. Please answer the ' \
82
+ 'following questions; if the question is not applicable to this module, feel free ' \
83
+ 'to leave it blank.',
80
84
  )
81
85
 
82
86
  begin
83
- puts ""
84
- forge_user = PDK::CLI::Input.get(_("What is your Puppet Forge username?"), Etc.getlogin)
87
+ puts ''
88
+ forge_user = PDK::CLI::Input.get(_('What is your Puppet Forge username?'), metadata.data['author'])
85
89
  metadata.update!('name' => "#{forge_user}-#{opts[:name]}")
86
90
  rescue StandardError => e
87
- PDK.logger.error(_("We're sorry, we could not parse your module name: %{message}") % {:message => e.message})
91
+ PDK.logger.error(_("We're sorry, we could not parse your module name: %{message}") % { message: e.message })
88
92
  retry
89
93
  end
90
94
 
91
95
  begin
92
- puts "\n" + _("Puppet uses Semantic Versioning (semver.org) to version modules.")
93
- module_version = PDK::CLI::Input.get(_("What version is this module?"), metadata.data['version'])
96
+ puts "\n" + _('Puppet uses Semantic Versioning (semver.org) to version modules.')
97
+ module_version = PDK::CLI::Input.get(_('What version is this module?'), metadata.data['version'])
94
98
  metadata.update!('version' => module_version)
95
99
  rescue StandardError => e
96
- PDK.logger.error(_("We're sorry, we could not parse that as a Semantic Version: %{message}") % {message: e.message})
100
+ PDK.logger.error(_("We're sorry, we could not parse that as a Semantic Version: %{message}") % { message: e.message })
97
101
  retry
98
102
  end
99
103
 
100
- puts ""
101
- module_author = PDK::CLI::Input.get(_("Who wrote this module?"), metadata.data['author'])
104
+ puts ''
105
+ module_author = PDK::CLI::Input.get(_('Who wrote this module?'), metadata.data['author'])
102
106
  metadata.update!('author' => module_author)
103
107
 
104
- unless opts.has_key?(:license)
105
- puts ""
106
- module_license = PDK::CLI::Input.get(_("What license does this module code fall under?"), metadata.data['license'])
108
+ unless opts.key?(:license)
109
+ puts ''
110
+ module_license = PDK::CLI::Input.get(_('What license does this module code fall under?'), metadata.data['license'])
107
111
  metadata.update!('license' => module_license)
108
112
  end
109
113
 
110
- puts ""
111
- module_summary = PDK::CLI::Input.get(_("How would you describe this module in a single sentence?"))
114
+ puts ''
115
+ module_summary = PDK::CLI::Input.get(_('How would you describe this module in a single sentence?'), metadata.data['summary'])
112
116
  metadata.update!('summary' => module_summary)
113
117
 
114
- puts ""
115
- module_source = PDK::CLI::Input.get(_("Where is this module's source code repository?"))
118
+ puts ''
119
+ module_source = PDK::CLI::Input.get(_("Where is this module's source code repository?"), metadata.data['source'])
116
120
  metadata.update!('source' => module_source)
117
121
 
118
- puts ""
119
- module_page = PDK::CLI::Input.get(_("Where can others go to learn more about this module?"), metadata.data['project_page'])
122
+ puts ''
123
+ module_page = PDK::CLI::Input.get(_('Where can others go to learn more about this module?'), metadata.data['project_page'])
120
124
  metadata.update!('project_page' => module_page)
121
125
 
122
- puts ""
123
- module_issues = PDK::CLI::Input.get(_("Where can others go to file issues about this module?"), metadata.data['issues_url'])
126
+ puts ''
127
+ module_issues = PDK::CLI::Input.get(_('Where can others go to file issues about this module?'), metadata.data['issues_url'])
124
128
  metadata.update!('issues_url' => module_issues)
125
129
 
126
130
  puts
@@ -129,8 +133,8 @@ module PDK
129
133
  puts '-' * 40
130
134
  puts
131
135
 
132
- if PDK::CLI::Input.get(_("About to generate this module; continue?"), 'Y') !~ /^y(es)?$/i
133
- puts _("Aborting...")
136
+ unless PDK::CLI::Input.get(_('About to generate this module; continue?'), 'Y') =~ %r{^y(es)?$}i # rubocop:disable Style/GuardClause
137
+ puts _('Aborting...')
134
138
  exit 0
135
139
  end
136
140
  end
@@ -10,7 +10,7 @@ module PDK
10
10
  # @return [Hash{Symbol => Object}] a hash of information that will be
11
11
  # provided to the class and class spec templates during rendering.
12
12
  def template_data
13
- data = {name: object_name}
13
+ data = { name: object_name }
14
14
  if @options.key?(:params)
15
15
  data[:params] = @options[:params]
16
16
  data[:max_type_length] = @options[:params].map { |r| r[:type].length }.max
@@ -31,14 +31,14 @@ module PDK
31
31
  @module_dir = module_dir
32
32
  @options = options
33
33
 
34
- if [:class, :defined_type].include?(object_type)
34
+ if [:class, :defined_type].include?(object_type) # rubocop:disable Style/GuardClause
35
35
  object_name_parts = object_name.split('::')
36
36
 
37
- if object_name_parts.first == module_name
38
- @object_name = object_name
39
- else
40
- @object_name = [module_name, object_name].join('::')
41
- end
37
+ @object_name = if object_name_parts.first == module_name
38
+ object_name
39
+ else
40
+ [module_name, object_name].join('::')
41
+ end
42
42
  end
43
43
  end
44
44
 
@@ -84,12 +84,12 @@ module PDK
84
84
  def run
85
85
  [target_object_path, target_spec_path].each do |target_file|
86
86
  if File.exist?(target_file)
87
- raise PDK::CLI::FatalError, _("Unable to generate class, '%{file}' already exists.") % {file: target_file}
87
+ raise PDK::CLI::FatalError, _("Unable to generate class, '%{file}' already exists.") % { file: target_file }
88
88
  end
89
89
  end
90
90
 
91
91
  with_templates do |template_path, config_hash|
92
- data = template_data.merge(:configs => config_hash)
92
+ data = template_data.merge(configs: config_hash)
93
93
 
94
94
  render_file(target_object_path, template_path[:object], data)
95
95
  render_file(target_spec_path, template_path[:spec], data) if template_path[:spec]
@@ -109,7 +109,7 @@ module PDK
109
109
  #
110
110
  # @api private
111
111
  def render_file(dest_path, template_path, data)
112
- PDK.logger.info(_("Creating %{file} from template.") % {file: dest_path})
112
+ PDK.logger.info(_("Creating '%{file}' from template.") % { file: dest_path })
113
113
  file_content = PDK::TemplateFile.new(template_path, data).render
114
114
  FileUtils.mkdir_p(File.dirname(dest_path))
115
115
  File.open(dest_path, 'w') { |f| f.write file_content }
@@ -132,7 +132,7 @@ module PDK
132
132
  def with_templates
133
133
  templates.each do |template|
134
134
  if template[:url].nil?
135
- PDK.logger.debug(_("No %{dir_type} template specified; trying next template directory.") % {dir_type: template[:type]})
135
+ PDK.logger.debug(_('No %{dir_type} template specified; trying next template directory.') % { dir_type: template[:type] })
136
136
  next
137
137
  end
138
138
 
@@ -142,13 +142,12 @@ module PDK
142
142
  if template_paths
143
143
  config_hash = template_dir.object_config
144
144
  yield template_paths, config_hash
145
- return
145
+ # TODO: refactor to a search-and-execute form instead
146
+ return # work is done # rubocop:disable Lint/NonLocalExitFromIterator
147
+ elsif template[:allow_fallback]
148
+ PDK.logger.debug(_('Unable to find a %{type} template in %{url}, trying next template directory') % { type: object_type, url: template[:url] })
146
149
  else
147
- if template[:allow_fallback]
148
- PDK.logger.debug(_("Unable to find a %{type} template in %{url}, trying next template directory") % {type: object_type, url: template[:url]})
149
- else
150
- raise PDK::CLI::FatalError, _("Unable to find the %{type} template in %{url}.") % {type: object_type, url: template[:url]}
151
- end
150
+ raise PDK::CLI::FatalError, _('Unable to find the %{type} template in %{url}.') % { type: object_type, url: template[:url] }
152
151
  end
153
152
  end
154
153
  end
@@ -176,9 +175,9 @@ module PDK
176
175
  # @api private
177
176
  def templates
178
177
  @templates ||= [
179
- {type: 'CLI', url: @options[:'template-url'], allow_fallback: false},
180
- {type: 'metadata', url: module_metadata.data['template-url'], allow_fallback: true},
181
- {type: 'default', url: PDK::Generate::Module::DEFAULT_TEMPLATE, allow_fallback: false},
178
+ { type: 'CLI', url: @options[:'template-url'], allow_fallback: false },
179
+ { type: 'metadata', url: module_metadata.data['template-url'], allow_fallback: true },
180
+ { type: 'default', url: PDK::Generate::Module::DEFAULT_TEMPLATE, allow_fallback: false },
182
181
  ]
183
182
  end
184
183
 
@@ -205,7 +204,7 @@ module PDK
205
204
  @module_metadata ||= begin
206
205
  PDK::Module::Metadata.from_file(File.join(module_dir, 'metadata.json'))
207
206
  rescue ArgumentError => e
208
- raise PDK::CLI::FatalError, _("'%{dir}' does not contain valid Puppet module metadata; %{msg}") % {dir: module_dir, msg: e.message}
207
+ raise PDK::CLI::FatalError, _("'%{dir}' does not contain valid Puppet module metadata: %{msg}") % { dir: module_dir, msg: e.message }
209
208
  end
210
209
  end
211
210
  end
data/lib/pdk/logger.rb CHANGED
@@ -11,7 +11,7 @@ module PDK
11
11
  super(STDOUT)
12
12
 
13
13
  # TODO: Decide on output format.
14
- self.formatter = proc do |severity,datetime,progname,msg|
14
+ self.formatter = proc do |severity, _datetime, _progname, msg|
15
15
  "pdk (#{severity}): #{msg}\n"
16
16
  end
17
17
 
@@ -3,21 +3,38 @@ require 'json'
3
3
  module PDK
4
4
  module Module
5
5
  class Metadata
6
-
7
6
  attr_accessor :data
8
7
 
9
8
  DEFAULTS = {
10
9
  'name' => nil,
11
10
  'version' => nil,
12
11
  'author' => nil,
13
- 'summary' => nil,
12
+ 'summary' => '',
14
13
  'license' => 'Apache-2.0',
15
14
  'source' => '',
16
15
  'project_page' => nil,
17
16
  'issues_url' => nil,
18
17
  'dependencies' => Set.new.freeze,
19
18
  'data_provider' => nil,
20
- }
19
+ 'operatingsystem_support' => [
20
+ {
21
+ 'operatingsystem' => 'Debian',
22
+ 'operatingsystemrelease' => ['8'],
23
+ },
24
+ {
25
+ 'operatingsystem' => 'RedHat',
26
+ 'operatingsystemrelease' => ['7.0'],
27
+ },
28
+ {
29
+ 'operatingsystem' => 'Ubuntu',
30
+ 'operatingsystemrelease' => ['16.04'],
31
+ },
32
+ {
33
+ 'operatingsystem' => 'Windows',
34
+ 'operatingsystemrelease' => ['2016'],
35
+ },
36
+ ],
37
+ }.freeze
21
38
 
22
39
  def initialize(params = {})
23
40
  @data = DEFAULTS.dup
@@ -26,17 +43,17 @@ module PDK
26
43
 
27
44
  def self.from_file(metadata_json_path)
28
45
  unless File.file?(metadata_json_path)
29
- raise ArgumentError, _("'%{file}' does not exist or is not a file") % {file: metadata_json_path}
46
+ raise ArgumentError, _("'%{file}' does not exist or is not a file") % { file: metadata_json_path }
30
47
  end
31
48
 
32
49
  unless File.readable?(metadata_json_path)
33
- raise ArgumentError, _("Unable to open '%{file}' for reading") % {file: metadata_json_path}
50
+ raise ArgumentError, _("Unable to open '%{file}' for reading") % { file: metadata_json_path }
34
51
  end
35
52
 
36
53
  begin
37
54
  data = JSON.parse(File.read(metadata_json_path))
38
55
  rescue JSON::JSONError => e
39
- raise ArgumentError, _("Invalid JSON in metadata.json: %{msg}") % {msg: e.message}
56
+ raise ArgumentError, _('Invalid JSON in metadata.json: %{msg}') % { msg: e.message }
40
57
  end
41
58
 
42
59
  new(data)
@@ -58,28 +75,28 @@ module PDK
58
75
  # Do basic validation and parsing of the name parameter.
59
76
  def process_name(data)
60
77
  validate_name(data['name'])
61
- author, module_name = data['name'].split(/[-\/]/, 2)
78
+ author, _modname = data['name'].split(%r{[-/]}, 2)
62
79
 
63
80
  data['author'] ||= author if @data['author'] == DEFAULTS['author']
64
81
  end
65
82
 
66
83
  # Validates that the given module name is both namespaced and well-formed.
67
84
  def validate_name(name)
68
- return if name =~ /\A[a-z0-9]+[-\/][a-z][a-z0-9_]*\Z/i
85
+ return if name =~ %r{\A[a-z0-9]+[-\/][a-z][a-z0-9_]*\Z}i
69
86
 
70
- namespace, modname = name.split(/[-\/]/, 2)
87
+ namespace, modname = name.split(%r{[-/]}, 2)
71
88
  modname = :namespace_missing if namespace == ''
72
89
 
73
90
  err = case modname
74
- when nil, '', :namespace_missing
75
- "the field must be a dash-separated username and module name"
76
- when /[^a-z0-9_]/i
77
- "the module name contains non-alphanumeric (or underscore) characters"
78
- when /^[^a-z]/i
79
- "the module name must begin with a letter"
80
- else
81
- "the namespace contains non-alphanumeric characters"
82
- end
91
+ when nil, '', :namespace_missing
92
+ 'the field must be a dash-separated username and module name'
93
+ when %r{[^a-z0-9_]}i
94
+ 'the module name contains non-alphanumeric (or underscore) characters'
95
+ when %r{^[^a-z]}i
96
+ 'the module name must begin with a letter'
97
+ else
98
+ 'the namespace contains non-alphanumeric characters'
99
+ end
83
100
 
84
101
  raise ArgumentError, "Invalid 'name' field in metadata.json: #{err}"
85
102
  end