opt_parse_validator 0.0.13 → 0.0.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07e2cf108f44ced6d598e64cc670a884ce7f07d3
4
- data.tar.gz: 2df6f9b8762e49d5fc9ab23a43e1225e956cb9e3
3
+ metadata.gz: e5a2531d386b9187b5ca2c26cd56888d10aa4b99
4
+ data.tar.gz: 3cc67811d22d44505c9ef4028142f30ed4231f68
5
5
  SHA512:
6
- metadata.gz: b272dba6c7e5cb56104d2fb361d76b9d792369707dcff1e53b9f21672a47c72664a5723a3e7c4fb602159608f59cddf718a7209081e17e5336b4a542c450d9db
7
- data.tar.gz: 0210003389f1f445f1613c35a71565dc212e82a007661dc9b2e3c5e9e041f55a42eebbe204d39694eb9d25f8ab0855775226c94e50880fb1fb03aa4486d0a560
6
+ metadata.gz: ed3fbe7b90c8cd35f4c185b3cd1883adbde479d78eb7c98a7d6da5e2bb4283add0c3154abb30eb975692ee320e7f6160fc01f4a182751eaaf93bce8ef0d111ab
7
+ data.tar.gz: 423bbd205f6db1a201d224ce9723e2adc507335d293471fe0c94f5d88ce50cefb45623d687bf6174189fa8ce5367e5d0b94360b77b9a3d00c8c9cd15b5b21b8a
data/README.md CHANGED
@@ -31,6 +31,7 @@ OptParseValidator
31
31
  - MultiChoices
32
32
  - choices (mandatory)
33
33
  - separator (default: ',')
34
+ - value_if_empty
34
35
  - incompatible
35
36
  - Positive Integer
36
37
  - Path
@@ -4,7 +4,7 @@ class OptionParser
4
4
  # See https://github.com/wpscanteam/CMSScanner/issues/2
5
5
  module Completion
6
6
  class << self
7
- alias_method :original_candidate, :candidate
7
+ alias original_candidate candidate
8
8
 
9
9
  def candidate(key, icase = false, pat = nil, &block)
10
10
  # Maybe also do this for -v/--version ?
@@ -4,9 +4,9 @@ module OptParseValidator
4
4
  module OptionsFile
5
5
  # Json Implementation
6
6
  class JSON < Base
7
- # @return [ Hash ] a { key: value } hash
7
+ # @return [ Hash ] a { 'key' => value } hash
8
8
  def parse
9
- ::JSON.parse(File.read(path), symbolize_names: true)
9
+ ::JSON.parse(File.read(path))
10
10
  end
11
11
  end
12
12
  end
@@ -4,9 +4,9 @@ module OptParseValidator
4
4
  module OptionsFile
5
5
  # Yaml Implementation
6
6
  class YML < Base
7
- # @return [ Hash ] a { key: value } hash
7
+ # @return [ Hash ] a { 'key' => value } hash
8
8
  def parse
9
- Hash[YAML.load_file(path).map { |k, v| [k.to_sym, v] }]
9
+ YAML.load_file(path) || {}
10
10
  end
11
11
  end
12
12
  end
@@ -32,12 +32,11 @@ module OptParseValidator
32
32
  def parse
33
33
  files_data = {}
34
34
 
35
- each do |option_file|
36
- data = option_file.parse
37
- files_data.merge!(data) if data
38
- end
35
+ each { |option_file| files_data.merge!(option_file.parse) }
39
36
 
40
- files_data
37
+ # Convert string-full keys to symbol ones
38
+ # No need to go deeper than the first level as it's the max depth
39
+ Hash[files_data.map { |k, v| [k.to_sym, v] }]
41
40
  end
42
41
  end
43
42
  end
@@ -85,7 +85,7 @@ module OptParseValidator
85
85
 
86
86
  fail Error, "Could not find option symbol for #{option}" unless long_option
87
87
 
88
- @symbol = long_option.gsub(/^--/, '').gsub(/-/, '_').to_sym
88
+ @symbol = long_option.gsub(/^--/, '').tr('-', '_').to_sym
89
89
  end
90
90
  @symbol
91
91
  end
@@ -95,7 +95,7 @@ module OptParseValidator
95
95
  option.each do |option_attr|
96
96
  if option_attr =~ /^--/
97
97
  return option_attr.gsub(/ .*$/, '')
98
- .gsub(/\[[^\]]+\]/, '')
98
+ .gsub(/\[[^\]]+\]/, '')
99
99
  end
100
100
  end
101
101
  nil
@@ -8,13 +8,10 @@ module OptParseValidator
8
8
  def validate(value)
9
9
  value = value.to_s
10
10
 
11
- if value.match(TRUE_PATTERN)
12
- return true
13
- elsif value.match(FALSE_PATTERN)
14
- return false
15
- else
16
- fail Error, 'Invalid boolean value, expected true|t|yes|y|1|false|f|no|n|0'
17
- end
11
+ return true if value.match(TRUE_PATTERN)
12
+ return false if value.match(FALSE_PATTERN)
13
+
14
+ fail Error, 'Invalid boolean value, expected true|t|yes|y|1|false|f|no|n|0'
18
15
  end
19
16
  end
20
17
  end
@@ -21,7 +21,7 @@ module OptParseValidator
21
21
  option << "Multiple choices can be supplied, use the '#{separator}' char as a separator"
22
22
  option << "If no choice is supplied, '#{value_if_empty}' will be used" if value_if_empty
23
23
 
24
- append_incomptable_help_messages
24
+ append_incompatible_help_messages
25
25
  end
26
26
 
27
27
  def append_choices_help_messages
@@ -32,7 +32,7 @@ module OptParseValidator
32
32
  other_lines_prefix = ' ' * first_line_prefix.size
33
33
 
34
34
  opt_help_messages(opt).each_with_index do |message, index|
35
- option << "#{index == 0 ? first_line_prefix : other_lines_prefix} #{message}"
35
+ option << "#{index.zero? ? first_line_prefix : other_lines_prefix} #{message}"
36
36
  end
37
37
  end
38
38
  end
@@ -44,7 +44,7 @@ module OptParseValidator
44
44
  opt.help_messages.empty? ? [opt.to_s.humanize] : opt.help_messages
45
45
  end
46
46
 
47
- def append_incomptable_help_messages
47
+ def append_incompatible_help_messages
48
48
  return if incompatible.empty?
49
49
 
50
50
  option << 'Incompatible choices (only one of each group/s can be used):'
@@ -78,7 +78,7 @@ module OptParseValidator
78
78
  # @return [ Array ]
79
79
  def value_from_pattern(item)
80
80
  choices.each do |key, opt|
81
- next unless item.match(/\A#{key.to_s}(.*)\z/)
81
+ next unless item =~ /\A#{key.to_s}(.*)\z/
82
82
 
83
83
  return [opt, Regexp.last_match[1]]
84
84
  end
@@ -20,7 +20,7 @@ module OptParseValidator
20
20
  path = Pathname.new(value)
21
21
  allowed_attrs.each do |key|
22
22
  method = "check_#{key}"
23
- send(method, path) if self.respond_to?(method) && attrs[key]
23
+ send(method, path) if respond_to?(method) && attrs[key]
24
24
  end
25
25
 
26
26
  path.to_s
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module OptParseValidator
3
- VERSION = '0.0.13'
3
+ VERSION = '0.0.13.2'.freeze
4
4
  end
@@ -68,7 +68,7 @@ module OptParseValidator
68
68
  # @return [ Hash ]
69
69
  def results(argv = default_argv)
70
70
  load_options_files
71
- self.parse!(argv)
71
+ parse!(argv)
72
72
  post_processing
73
73
 
74
74
  @results
@@ -84,7 +84,7 @@ module OptParseValidator
84
84
  @opts.each do |opt|
85
85
  next unless files_data.key?(opt.to_sym)
86
86
 
87
- @results[opt.to_sym] = opt.normalize(opt.validate(files_data[opt.to_sym]))
87
+ @results[opt.to_sym] = opt.normalize(opt.validate(files_data[opt.to_sym].to_s))
88
88
  end
89
89
  end
90
90
 
@@ -32,13 +32,13 @@ Gem::Specification.new do |s|
32
32
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
33
  s.require_paths = ['lib']
34
34
 
35
- s.add_dependency 'addressable', '~> 2.3'
36
- s.add_dependency 'activesupport', '~> 4.2'
35
+ s.add_dependency 'addressable', '~> 2.4.0'
36
+ s.add_dependency 'activesupport', '~> 5.0.0.0'
37
37
 
38
- s.add_development_dependency 'rake', '~> 10.4'
39
- s.add_development_dependency 'rspec', '~> 3.3'
40
- s.add_development_dependency 'rspec-its', '~> 1.2'
38
+ s.add_development_dependency 'rake', '~> 11.3.0'
39
+ s.add_development_dependency 'rspec', '~> 3.5.0'
40
+ s.add_development_dependency 'rspec-its', '~> 1.2.0'
41
41
  s.add_development_dependency 'bundler', '~> 1.6'
42
- s.add_development_dependency 'rubocop', '~> 0.32'
43
- s.add_development_dependency 'simplecov', '~> 0.10'
42
+ s.add_development_dependency 'rubocop', '~> 0.43.0'
43
+ s.add_development_dependency 'simplecov', '~> 0.12.0'
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opt_parse_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.3'
19
+ version: 2.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.3'
26
+ version: 2.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: 5.0.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: 5.0.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.4'
47
+ version: 11.3.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.4'
54
+ version: 11.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.3'
61
+ version: 3.5.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.3'
68
+ version: 3.5.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
75
+ version: 1.2.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.2'
82
+ version: 1.2.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.32'
103
+ version: 0.43.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.32'
110
+ version: 0.43.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.10'
117
+ version: 0.12.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.10'
124
+ version: 0.12.0
125
125
  description: Implementation of validators for the ruby OptionParser lib. Mainly used
126
126
  in the CMSScanner gem to define the cli options available
127
127
  email:
@@ -185,4 +185,3 @@ signing_key:
185
185
  specification_version: 4
186
186
  summary: Ruby OptionParser Validators
187
187
  test_files: []
188
- has_rdoc: