ocg 1.1.1 → 1.2.0
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 +4 -4
- data/README.md +28 -31
- data/lib/ocg/main.rb +4 -4
- data/lib/ocg/operator/abstract.rb +3 -1
- data/lib/ocg/options.rb +2 -2
- data/lib/ocg/version.rb +1 -1
- metadata +43 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52b0c6aa85ed30a2ae8c65d872e90136d223822fc8d970c26c6515f56ee84b98
|
4
|
+
data.tar.gz: 248d46514c8fba336fef0347f5d21d40752651cfc4b3846110e69480f8da02a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15fb346aa655fe3cf505439073ccdd8156c1b341b5ddd38ef4ce7a7e89e4982f2c5ebad4e43ebe3bde8172bd2c46776d9a154db37b2acab94bdcd088df5afb69
|
7
|
+
data.tar.gz: 4ff7e04a1684f0c073f0366360d1145e0bdaf9323a6d03ff2c828756bf88c53ecf7eae79b2055f3ccce5605c558b09d6804202d1cdc29d1d069e8b1adc0199f2
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Option combination generator
|
2
2
|
|
3
|
-
| Travis | AppVeyor |
|
4
|
-
| :---: | :---: | :---: | :---:
|
5
|
-
| [](https://travis-ci.com/andrew-aladev/ocg) | [](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [](https://travis-ci.com/andrew-aladev/ocg) | [](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [](https://circleci.com/gh/andrew-aladev/ocg/tree/master) | [](https://codecov.io/gh/andrew-aladev/ocg) | [](https://rubygems.org/gems/ocg) |
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -17,6 +17,8 @@ rake gem
|
|
17
17
|
gem install pkg/ocg-*.gem
|
18
18
|
```
|
19
19
|
|
20
|
+
You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
|
21
|
+
|
20
22
|
## Usage
|
21
23
|
|
22
24
|
```ruby
|
@@ -39,13 +41,31 @@ generator = OCG.new(
|
|
39
41
|
:h => 7..8
|
40
42
|
)
|
41
43
|
|
42
|
-
|
44
|
+
generator.each { |combination| puts combination }
|
43
45
|
```
|
44
46
|
|
45
47
|
It will populate all option combinations.
|
46
48
|
|
47
49
|
## Docs
|
48
50
|
|
51
|
+
`OCG.new options` will prepare a generator.
|
52
|
+
It will provide all possible option combinations.
|
53
|
+
|
54
|
+
| Method | Description |
|
55
|
+
|-------------|-------------|
|
56
|
+
| `and` | provides all combinations between generators |
|
57
|
+
| `mix` | merges combinations without combining, guarantees that both left and right generator combinations will be provided at least once |
|
58
|
+
| `or` | concats generator combinations without merging |
|
59
|
+
| `reset` | allows to receive combinations once again |
|
60
|
+
| `next` | returns next combination |
|
61
|
+
| `last` | returns last combination |
|
62
|
+
| `started?` | returns true when at least one combination was generated |
|
63
|
+
| `finished?` | returns true when all combination were generated |
|
64
|
+
| `length` | returns combinations length |
|
65
|
+
|
66
|
+
Generator is responsible to any method from [`Enumerable`](https://ruby-doc.org/core-2.7.2/Enumerable.html).
|
67
|
+
You can combine generators using `and`, `mix` and `or`.
|
68
|
+
|
49
69
|
Options should be prepared in the following form:
|
50
70
|
|
51
71
|
```ruby
|
@@ -60,29 +80,6 @@ Options hash should not be empty.
|
|
60
80
|
`option_values` should be convertable to array using `to_a`.
|
61
81
|
`option_values` should not be empty.
|
62
82
|
|
63
|
-
`OCG.new options` will prepare a generator.
|
64
|
-
It will provide all possible option combinations.
|
65
|
-
|
66
|
-
You can combine generators using `and`, `mix` and `or`.
|
67
|
-
|
68
|
-
`and` method will provide all combinations between generators.
|
69
|
-
`mix` method will merge combinations without combining. `mix` guarantees that both left and right generator combinations will be provided at least once.
|
70
|
-
`or` method will concat generator combinations without merging.
|
71
|
-
|
72
|
-
`reset` method allows to receive combinations once again.
|
73
|
-
|
74
|
-
`next` method returns next combination.
|
75
|
-
|
76
|
-
`last` method returns last combination.
|
77
|
-
|
78
|
-
`started?` method returns true when at least one combination was generated.
|
79
|
-
|
80
|
-
`finished?` method returns true when all combination were generated.
|
81
|
-
|
82
|
-
`length` returns combinations length.
|
83
|
-
|
84
|
-
`to_a` returns combinations array.
|
85
|
-
|
86
83
|
## Why?
|
87
84
|
|
88
85
|
Many software uses multiple options and have complex relations between them.
|
@@ -159,10 +156,10 @@ complete_generator = almost_complete_generator.mix(
|
|
159
156
|
|
160
157
|
## CI
|
161
158
|
|
162
|
-
|
163
|
-
|
164
|
-
|
159
|
+
Please visit [scripts/test-images](scripts/test-images).
|
160
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
161
|
+
You can run this script using many native and cross images.
|
165
162
|
|
166
163
|
## License
|
167
164
|
|
168
|
-
MIT license, see LICENSE and AUTHORS.
|
165
|
+
MIT license, see [LICENSE](LICENSE) and [AUTHORS](AUTHORS).
|
data/lib/ocg/main.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative "error"
|
|
7
7
|
require_relative "options"
|
8
8
|
|
9
9
|
class OCG
|
10
|
+
include ::Enumerable
|
10
11
|
extend ::Forwardable
|
11
12
|
|
12
13
|
DELEGATORS = %i[reset next last started? finished? length].freeze
|
@@ -35,15 +36,14 @@ class OCG
|
|
35
36
|
Operator::OR.new self, generator_or_options
|
36
37
|
end
|
37
38
|
|
38
|
-
def
|
39
|
+
def each(&_block)
|
39
40
|
reset
|
40
41
|
|
41
|
-
|
42
|
-
result << send("next") until finished?
|
42
|
+
yield send("next") until finished?
|
43
43
|
|
44
44
|
reset
|
45
45
|
|
46
|
-
|
46
|
+
nil
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -6,7 +6,7 @@ require_relative "../error"
|
|
6
6
|
class OCG
|
7
7
|
module Operator
|
8
8
|
class Abstract < OCG
|
9
|
-
def initialize(left_generator_or_options, right_generator_or_options)
|
9
|
+
def initialize(left_generator_or_options, right_generator_or_options) # rubocop:disable Lint/MissingSuper
|
10
10
|
@left_generator = OCG.prepare_generator left_generator_or_options
|
11
11
|
@right_generator = OCG.prepare_generator right_generator_or_options
|
12
12
|
|
@@ -20,6 +20,7 @@ class OCG
|
|
20
20
|
nil
|
21
21
|
end
|
22
22
|
|
23
|
+
# :nocov:
|
23
24
|
def next
|
24
25
|
raise NotImplementedError, "\"next\" is not implemented"
|
25
26
|
end
|
@@ -39,6 +40,7 @@ class OCG
|
|
39
40
|
def length
|
40
41
|
raise NotImplementedError, "\"length\" is not implemented"
|
41
42
|
end
|
43
|
+
# :nocov:
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
data/lib/ocg/options.rb
CHANGED
@@ -7,7 +7,7 @@ class OCG
|
|
7
7
|
class Options
|
8
8
|
def initialize(options)
|
9
9
|
Validation.validate_options options
|
10
|
-
@options =
|
10
|
+
@options = options.transform_values(&:to_a)
|
11
11
|
|
12
12
|
# End to start is more traditional way of making combinations.
|
13
13
|
@keys = @options.keys.reverse
|
@@ -20,7 +20,7 @@ class OCG
|
|
20
20
|
end
|
21
21
|
|
22
22
|
protected def reset_value_indexes
|
23
|
-
@value_indexes =
|
23
|
+
@value_indexes = @options.transform_values { |_values| 0 }
|
24
24
|
end
|
25
25
|
|
26
26
|
def reset
|
data/lib/ocg/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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:
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: codecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
33
|
+
version: '5.14'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5.
|
40
|
+
version: '5.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rubocop
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
61
|
+
version: '0.93'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
68
|
+
version: '0.93'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rubocop-performance
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
75
|
+
version: '1.8'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
80
|
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
82
|
+
version: '1.8'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: simplecov
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - "
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
89
|
+
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - "
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
96
|
+
version: '0'
|
69
97
|
description:
|
70
98
|
email: aladjev.andrew@gmail.com
|
71
99
|
executables: []
|
@@ -97,14 +125,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
125
|
requirements:
|
98
126
|
- - ">="
|
99
127
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
128
|
+
version: '2.5'
|
101
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
130
|
requirements:
|
103
131
|
- - ">="
|
104
132
|
- !ruby/object:Gem::Version
|
105
133
|
version: '0'
|
106
134
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.1.4
|
108
136
|
signing_key:
|
109
137
|
specification_version: 4
|
110
138
|
summary: Option combination generator.
|