ocg 1.3.1 → 1.4.0

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
  SHA256:
3
- metadata.gz: 1f1bbd2f95185a3f9098a0e861afbcdc5372126c0956adc4b32547c26a22dc35
4
- data.tar.gz: 79c9230bcca50efb4cebd233dc16f68e7ac871499c8ce7e519557e56e5cb17cf
3
+ metadata.gz: 0fa3d1a73808ebe1197e76243c66e4d00b0220c4bbe398e2fcf11e1f58c0f243
4
+ data.tar.gz: 8709140dacba810330d6ec2b4889002e0a432a1acd4e5af3767ed3a91cded7a4
5
5
  SHA512:
6
- metadata.gz: 8ff79d40bcf1a14c77809a4c8662aae70c5d597aa5c7be693fa337ea06bf826704ac1ef7ba27177620337cba8bf9b966752ba836e07d5276c798db17c3cee5e8
7
- data.tar.gz: 8ef828c80ddc4709b0c7030876f2a06a30954662d8397c06afdb7fc313d93f4283a81664db4bf73d56bdee315ff713d74fe015a15829619e03f41f501a660153
6
+ metadata.gz: 374148f48f17496aa4d6c572c6e091d08f12b79a8bc1172c2605cb91d30bc1e9a70bda8591fc28e96b1445895c17c930f9dff0b96e5c0460a98d3ed67a9e8b3a
7
+ data.tar.gz: 1f403b651a77e2b905543008ba198ddbf6ac6eb02dac413de5aab076458d2386815b6c6baf42b77025790273d108e0ba3b13649c7a56ea49e2940dd6245f9a04
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  ## Installation
8
8
 
9
+ Operating systems: GNU/Linux, OSX, FreeBSD, Windows.
10
+
9
11
  ```sh
10
12
  gem install ocg
11
13
  ```
@@ -65,7 +67,7 @@ It will provide all possible option combinations.
65
67
  | `dup` | returns generator duplicate |
66
68
  | `clone` | returns generator clone |
67
69
 
68
- Generator is responsible to any method from [`Enumerable`](https://ruby-doc.org/core-3.0.0/Enumerable.html).
70
+ Generator is responsible to any method from [`Enumerable`](https://ruby-doc.org/core-3.0.1/Enumerable.html).
69
71
  Enumerator will be provided using generator duplicate.
70
72
  So enumerable api is separated from bare metal api (`reset`, `next`, `last`, `started?`, `finished?`).
71
73
 
@@ -80,7 +82,7 @@ Options should be prepared in the following form:
80
82
  }
81
83
  ```
82
84
 
83
- Options hash should not be empty.
85
+ Options hash may be empty.
84
86
  `option_name` can be any valid hash key.
85
87
  `option_values` should be convertable to array using `to_a`.
86
88
  `option_values` should not be empty.
@@ -159,15 +161,10 @@ complete_generator = almost_complete_generator.mix(
159
161
  )
160
162
  ```
161
163
 
162
- ## Operating systems
163
-
164
- GNU/Linux, FreeBSD, OSX, Windows (MinGW).
165
-
166
164
  ## CI
167
165
 
168
166
  Please visit [scripts/test-images](scripts/test-images).
169
167
  See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
170
- You can run this script using many native and cross images.
171
168
 
172
169
  ## License
173
170
 
data/lib/ocg/main.rb CHANGED
@@ -17,7 +17,7 @@ class OCG
17
17
 
18
18
  def_delegators :@generator, *DELEGATORS
19
19
 
20
- def initialize(generator_or_options)
20
+ def initialize(generator_or_options = {})
21
21
  @generator = self.class.prepare_generator generator_or_options
22
22
  end
23
23
 
@@ -27,15 +27,15 @@ class OCG
27
27
  Options.new generator_or_options
28
28
  end
29
29
 
30
- def and(generator_or_options)
30
+ def and(generator_or_options = {})
31
31
  Operator::AND.new self, generator_or_options
32
32
  end
33
33
 
34
- def mix(generator_or_options)
34
+ def mix(generator_or_options = {})
35
35
  Operator::MIX.new self, generator_or_options
36
36
  end
37
37
 
38
- def or(generator_or_options)
38
+ def or(generator_or_options = {})
39
39
  Operator::OR.new self, generator_or_options
40
40
  end
41
41
 
@@ -22,6 +22,16 @@ class OCG
22
22
  nil
23
23
  end
24
24
 
25
+ protected def merge_results(left, right)
26
+ if left.nil?
27
+ right
28
+ elsif right.nil?
29
+ left
30
+ else
31
+ left.merge right
32
+ end
33
+ end
34
+
25
35
  # :nocov:
26
36
  def next
27
37
  raise NotImplementedError, "\"next\" is not implemented"
@@ -11,21 +11,22 @@ class OCG
11
11
 
12
12
  if @right_generator.finished?
13
13
  @right_generator.reset
14
- @left_generator.next.merge @right_generator.next
14
+ left = @left_generator.next
15
15
  else
16
- left_last = @left_generator.last
17
- left_last = @left_generator.next if left_last.nil?
18
- left_last.merge @right_generator.next
16
+ left = @left_generator.last
17
+ left = @left_generator.next if left.nil?
19
18
  end
19
+
20
+ right = @right_generator.next
21
+
22
+ merge_results left, right
20
23
  end
21
24
 
22
25
  def last
23
- left_last = @left_generator.last
24
- right_last = @right_generator.last
25
-
26
- return nil if left_last.nil? || right_last.nil?
26
+ left = @left_generator.last
27
+ right = @right_generator.last
27
28
 
28
- left_last.merge right_last
29
+ merge_results left, right
29
30
  end
30
31
 
31
32
  def started?
@@ -37,7 +38,16 @@ class OCG
37
38
  end
38
39
 
39
40
  def length
40
- @left_generator.length * @right_generator.length
41
+ left_length = @left_generator.length
42
+ right_length = @right_generator.length
43
+
44
+ if left_length.zero?
45
+ right_length
46
+ elsif right_length.zero?
47
+ left_length
48
+ else
49
+ left_length * right_length
50
+ end
41
51
  end
42
52
  end
43
53
  end
@@ -32,16 +32,18 @@ class OCG
32
32
 
33
33
  @left_generator.reset if @left_generator.finished?
34
34
  @right_generator.reset if @right_generator.finished?
35
- @left_generator.next.merge @right_generator.next
35
+
36
+ left = @left_generator.next
37
+ right = @right_generator.next
38
+
39
+ merge_results left, right
36
40
  end
37
41
 
38
42
  def last
39
- left_last = @left_generator.last
40
- right_last = @right_generator.last
41
-
42
- return nil if left_last.nil? || right_last.nil?
43
+ left = @left_generator.last
44
+ right = @right_generator.last
43
45
 
44
- left_last.merge right_last
46
+ merge_results left, right
45
47
  end
46
48
 
47
49
  def started?
@@ -17,13 +17,13 @@ class OCG
17
17
  end
18
18
 
19
19
  def last
20
- left_last = @left_generator.last
21
- right_last = @right_generator.last
20
+ left = @left_generator.last
21
+ right = @right_generator.last
22
22
 
23
- if right_last.nil?
24
- left_last
23
+ if right.nil?
24
+ left
25
25
  else
26
- right_last
26
+ right
27
27
  end
28
28
  end
29
29
 
data/lib/ocg/options.rb CHANGED
@@ -21,7 +21,7 @@ class OCG
21
21
 
22
22
  reset_value_indexes
23
23
 
24
- @is_finished = false
24
+ @is_finished = length.zero?
25
25
  end
26
26
 
27
27
  protected def reset_value_indexes
@@ -36,7 +36,7 @@ class OCG
36
36
  # If state is finished than all value indexes are already zero.
37
37
  reset_value_indexes unless @is_finished
38
38
 
39
- @is_finished = false
39
+ @is_finished = length.zero?
40
40
 
41
41
  nil
42
42
  end
@@ -44,7 +44,7 @@ class OCG
44
44
  def next
45
45
  return nil if @is_finished
46
46
 
47
- @last_options = Hash[@value_indexes.map { |name, value_index| [name, @options[name][value_index]] }]
47
+ @last_options = @value_indexes.map { |name, value_index| [name, @options[name][value_index]] }.to_h
48
48
 
49
49
  @is_finished = @keys.all? do |name|
50
50
  values = @options[name]
@@ -76,7 +76,13 @@ class OCG
76
76
  end
77
77
 
78
78
  def length
79
- @options.reduce(1) { |length, (_name, values)| length * values.length }
79
+ @options.reduce(0) do |length, (_name, values)|
80
+ if length.zero?
81
+ values.length
82
+ else
83
+ length * values.length
84
+ end
85
+ end
80
86
  end
81
87
  end
82
88
  end
@@ -7,7 +7,6 @@ class OCG
7
7
  module Validation
8
8
  def self.validate_options(options)
9
9
  raise ValidateError, "invalid options hash" unless options.is_a? ::Hash
10
- raise ValidateError, "options should not be empty" if options.empty?
11
10
 
12
11
  options.each do |_name, values|
13
12
  raise ValidateError, "option values should respond to \"to_a\"" unless values.respond_to? :to_a
data/lib/ocg/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
- VERSION = "1.3.1".freeze
5
+ VERSION = "1.4.0".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Aladjev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,56 +72,56 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.8'
75
+ version: '1.22'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.8'
82
+ version: '1.22'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop-minitest
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.10'
89
+ version: '0.15'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.10'
96
+ version: '0.15'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-performance
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '1.9'
103
+ version: '1.11'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '1.9'
110
+ version: '1.11'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop-rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0.5'
117
+ version: '0.6'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0.5'
124
+ version: '0.6'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
175
  - !ruby/object:Gem::Version
162
176
  version: '0'
163
177
  requirements: []
164
- rubygems_version: 3.2.3
178
+ rubygems_version: 3.2.22
165
179
  signing_key:
166
180
  specification_version: 4
167
181
  summary: Option combination generator.