opt_parse_validator 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f71cf9bbecec6b8c33d14c3cab01c0af1112735
4
- data.tar.gz: d033f1ef4649cd628d415657c2375d014616a3b2
3
+ metadata.gz: f77666c01d6e2405f194bb9571c77ffb90945dd0
4
+ data.tar.gz: 006b7e8a8f1497da7c30d32537c579669630b9ad
5
5
  SHA512:
6
- metadata.gz: 63b1f0f830f821e9639b5a6c239c20a472ba9fef16850fb7c37eabf54d589ca463bd30f087a7da906d9ee458a12a23f7162976a0d033a32c06aaec9531f9645a
7
- data.tar.gz: 66311acd02e0b17a87d653e5b12609d94a5138e7a1a915e63a401c23004e9c00499c236cf376bf33603f3135f15c38f4e40af229dcb0a4552f1131d3bed98aff
6
+ metadata.gz: 5f088679e26508b674b9bcc70c8fc036d29f9c501939df67cd6838aa341673af287e026117e5b23133fe24715ad29155d49d08a90e435b45a346106acb97a6bc
7
+ data.tar.gz: ad09a370941caa0b52d3ec7f74b2de5a9122cb5b31cff987e9e645fead9519f3550fb47ca8f1b43c74faf2729c1529c87151eefea5fbed13e9a5d2cbf2a84122
data/README.md CHANGED
@@ -31,6 +31,7 @@ OptParseValidator
31
31
  - MultiChoices
32
32
  - choices (mandatory)
33
33
  - separator (default: ',')
34
+ - incompatible
34
35
  - Positive Integer
35
36
  - Path
36
37
  - :file
@@ -4,6 +4,7 @@ module OptParseValidator
4
4
  # @param [ Array ] option See OptBase#new
5
5
  # @param [ Hash ] attrs
6
6
  # @option attrs [ Hash ] :choices
7
+ # @option attrs [ Array<Array> ] :incompatible
7
8
  # @options attrs [ String ] :separator See OptArray#new
8
9
  def initialize(option, attrs = {})
9
10
  fail 'The :choices attribute is mandatory' unless attrs.key?(:choices)
@@ -30,7 +31,7 @@ module OptParseValidator
30
31
  results[opt.to_sym] = opt.normalize(opt.validate(opt_value))
31
32
  end
32
33
 
33
- results
34
+ verify_compatibility(results)
34
35
  end
35
36
 
36
37
  # @return [ Array ]
@@ -44,6 +45,26 @@ module OptParseValidator
44
45
  fail "Unknown choice: #{item}"
45
46
  end
46
47
 
48
+ # @param [ Hash ] values
49
+ #
50
+ # @return [ Hash ]
51
+ def verify_compatibility(values)
52
+ [*attrs[:incompatible]].each do |a|
53
+ last_match = ''
54
+
55
+ a.each do |sym|
56
+ next unless values.key?(sym)
57
+
58
+ if last_match.empty?
59
+ last_match = sym
60
+ else
61
+ fail "Incompatible choices detected: #{last_match}, #{sym}"
62
+ end
63
+ end
64
+ end
65
+ values
66
+ end
67
+
47
68
  # No normalization
48
69
  def normalize(value)
49
70
  value
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module OptParseValidator
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
  end
@@ -5,8 +5,15 @@ describe OptParseValidator::OptMultiChoices do
5
5
  let(:attrs) do
6
6
  {
7
7
  choices: {
8
- vp: OptParseValidator::OptBoolean.new(['--vulenrable-plugins']),
9
- u: OptParseValidator::OptIntegerRange.new(['--users'], value_if_empty: '1-10')
8
+ vp: OptParseValidator::OptBoolean.new(['--vulnerable-plugins']),
9
+ ap: OptParseValidator::OptBoolean.new(['--all-plugins']),
10
+ p: OptParseValidator::OptBoolean.new(['--plugins']),
11
+ vt: OptParseValidator::OptBoolean.new(['--vulnerable-themes']),
12
+ at: OptParseValidator::OptBoolean.new(['--all-themes']),
13
+ t: OptParseValidator::OptBoolean.new(['--themes']),
14
+ tt: OptParseValidator::OptBoolean.new(['--timthumbs']),
15
+ u: OptParseValidator::OptIntegerRange.new(['--users'], value_if_empty: '1-10'),
16
+ m: OptParseValidator::OptIntegerRange.new(['--media'], value_if_empty: '1-100')
10
17
  }
11
18
  }
12
19
  end
@@ -58,16 +65,35 @@ describe OptParseValidator::OptMultiChoices do
58
65
 
59
66
  it 'returns the expected hash' do
60
67
  [nil, ''].each do |value|
61
- expect(opt.validate(value)).to eql(vulenrable_plugins: true, users: (1..10))
68
+ expect(opt.validate(value)).to eql(vulnerable_plugins: true, users: (1..10))
62
69
  end
63
70
  end
64
71
  end
65
72
  end
66
73
 
67
74
  context 'when value' do
75
+ let(:attrs) do
76
+ super().merge(incompatible: [
77
+ [:vulnerable_plugins, :all_plugins, :plugins],
78
+ [:vulnerable_themes, :all_themes, :themes]
79
+ ])
80
+ end
81
+
68
82
  it 'returns the expected hash' do
69
83
  expect(opt.validate('u2-5')).to eql(users: (2..5))
70
84
  end
85
+
86
+ context 'when incompatible choices given' do
87
+ it 'raises an error' do
88
+ {
89
+ 'ap,p,t' => 'all_plugins, plugins',
90
+ 'ap,t,vp' => 'vulnerable_plugins, all_plugins',
91
+ 'ap,at,t' => 'all_themes, themes'
92
+ }.each do |value, msg|
93
+ expect { opt.validate(value) }.to raise_error "Incompatible choices detected: #{msg}"
94
+ end
95
+ end
96
+ end
71
97
  end
72
98
  end
73
99
 
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam - Erwan le Rousseau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable