ocg 1.1.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -31
- data/lib/ocg/copyable.rb +17 -0
- data/lib/ocg/main.rb +12 -10
- data/lib/ocg/operator/abstract.rb +3 -1
- data/lib/ocg/operator/mix.rb +10 -0
- data/lib/ocg/options.rb +7 -2
- data/lib/ocg/version.rb +1 -1
- metadata +11 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3e653800a9ddc59e36ee81e45dd0a85b3e0120418c2155aa4d4a1a4b659d949
|
4
|
+
data.tar.gz: 3f22c5f598564d3c57844e8048258795b8868763912322b156e079ce966464b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32cb6bd02ff29e283d6e7acbc15c62c493bd5aa84855f3bc3dc18090bf7ce60fed2044dafcbf194fc60a0daa060bc6d411c821045fde54fbecfa63cff0c85292
|
7
|
+
data.tar.gz: 335fd3ee150a0386d28a30cbd234e0b258d2e7298989b3990728fbb125ae88fba057fcc6001bae8fcb8d6a35b2ae15c804fe8574a0537aa3daf25dd9a5e757c1
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Option combination generator
|
2
2
|
|
3
|
-
| Travis | AppVeyor |
|
4
|
-
| :---: | :---: | :---: | :---:
|
5
|
-
| [![Travis test status](https://travis-ci.com/andrew-aladev/ocg.svg?branch=master)](https://travis-ci.com/andrew-aladev/ocg) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ocg?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [![
|
3
|
+
| Travis | AppVeyor | Circle | Codecov | Gem |
|
4
|
+
| :---: | :---: | :---: | :---: | :---: |
|
5
|
+
| [![Travis test status](https://travis-ci.com/andrew-aladev/ocg.svg?branch=master)](https://travis-ci.com/andrew-aladev/ocg) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ocg?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ocg/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ocg/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ocg/tree/master) | [![Codecov](https://codecov.io/gh/andrew-aladev/ocg/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ocg) | [![Gem](https://img.shields.io/gem/v/ocg.svg)](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,36 @@ 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
|
+
| `dup` | returns generator duplicate |
|
66
|
+
| `clone` | returns generator clone |
|
67
|
+
|
68
|
+
Generator is responsible to any method from [`Enumerable`](https://ruby-doc.org/core-2.7.2/Enumerable.html).
|
69
|
+
Enumerator will be provided using generator duplicate.
|
70
|
+
So enumerable api is separated from bare metal api (`reset`, `next`, `last`, `started?`, `finished?`).
|
71
|
+
|
72
|
+
You can combine generators using `and`, `mix` and `or`.
|
73
|
+
|
49
74
|
Options should be prepared in the following form:
|
50
75
|
|
51
76
|
```ruby
|
@@ -60,29 +85,6 @@ Options hash should not be empty.
|
|
60
85
|
`option_values` should be convertable to array using `to_a`.
|
61
86
|
`option_values` should not be empty.
|
62
87
|
|
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
88
|
## Why?
|
87
89
|
|
88
90
|
Many software uses multiple options and have complex relations between them.
|
@@ -159,10 +161,10 @@ complete_generator = almost_complete_generator.mix(
|
|
159
161
|
|
160
162
|
## CI
|
161
163
|
|
162
|
-
|
163
|
-
|
164
|
-
|
164
|
+
Please visit [scripts/test-images](scripts/test-images).
|
165
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
166
|
+
You can run this script using many native and cross images.
|
165
167
|
|
166
168
|
## License
|
167
169
|
|
168
|
-
MIT license, see LICENSE and AUTHORS.
|
170
|
+
MIT license, see [LICENSE](LICENSE) and [AUTHORS](AUTHORS).
|
data/lib/ocg/copyable.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Option combination generator.
|
2
|
+
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
class OCG
|
5
|
+
module Copyable
|
6
|
+
VARIABLES_TO_COPY = [].freeze
|
7
|
+
|
8
|
+
def initialize_copy(source)
|
9
|
+
self.class::VARIABLES_TO_COPY.each do |variable|
|
10
|
+
key = "@#{variable}".to_sym
|
11
|
+
value = source.instance_variable_get key
|
12
|
+
|
13
|
+
instance_variable_set key, value.dup
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ocg/main.rb
CHANGED
@@ -3,13 +3,19 @@
|
|
3
3
|
|
4
4
|
require "forwardable"
|
5
5
|
|
6
|
+
require_relative "copyable"
|
6
7
|
require_relative "error"
|
7
8
|
require_relative "options"
|
8
9
|
|
9
10
|
class OCG
|
11
|
+
include Copyable
|
12
|
+
include ::Enumerable
|
10
13
|
extend ::Forwardable
|
11
14
|
|
12
|
-
DELEGATORS
|
15
|
+
DELEGATORS = %i[reset next last started? finished? length].freeze
|
16
|
+
VARIABLES_TO_COPY = %i[generator].freeze
|
17
|
+
|
18
|
+
def_delegators :@generator, *DELEGATORS
|
13
19
|
|
14
20
|
def initialize(generator_or_options)
|
15
21
|
@generator = self.class.prepare_generator generator_or_options
|
@@ -21,8 +27,6 @@ class OCG
|
|
21
27
|
Options.new generator_or_options
|
22
28
|
end
|
23
29
|
|
24
|
-
def_delegators :@generator, *DELEGATORS
|
25
|
-
|
26
30
|
def and(generator_or_options)
|
27
31
|
Operator::AND.new self, generator_or_options
|
28
32
|
end
|
@@ -35,15 +39,13 @@ class OCG
|
|
35
39
|
Operator::OR.new self, generator_or_options
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
result = []
|
42
|
-
result << send("next") until finished?
|
42
|
+
def each(&_block)
|
43
|
+
instance = dup
|
44
|
+
instance.reset
|
43
45
|
|
44
|
-
|
46
|
+
yield instance.next until instance.finished?
|
45
47
|
|
46
|
-
|
48
|
+
nil
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -6,7 +6,9 @@ require_relative "../error"
|
|
6
6
|
class OCG
|
7
7
|
module Operator
|
8
8
|
class Abstract < OCG
|
9
|
-
|
9
|
+
VARIABLES_TO_COPY = %i[left_generator right_generator].freeze
|
10
|
+
|
11
|
+
def initialize(left_generator_or_options, right_generator_or_options) # rubocop:disable Lint/MissingSuper
|
10
12
|
@left_generator = OCG.prepare_generator left_generator_or_options
|
11
13
|
@right_generator = OCG.prepare_generator right_generator_or_options
|
12
14
|
|
data/lib/ocg/operator/mix.rb
CHANGED
@@ -9,6 +9,16 @@ class OCG
|
|
9
9
|
def initialize(*args)
|
10
10
|
super
|
11
11
|
|
12
|
+
reset_main_generator
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize_copy(*args)
|
16
|
+
super
|
17
|
+
|
18
|
+
reset_main_generator
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset_main_generator
|
12
22
|
@main_generator =
|
13
23
|
if @right_generator.length > @left_generator.length
|
14
24
|
@right_generator
|
data/lib/ocg/options.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# Option combination generator.
|
2
2
|
# Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
+
require_relative "copyable"
|
4
5
|
require_relative "validation"
|
5
6
|
|
6
7
|
class OCG
|
7
8
|
class Options
|
9
|
+
include Copyable
|
10
|
+
|
11
|
+
VARIABLES_TO_COPY = %i[options keys last_options value_indexes].freeze
|
12
|
+
|
8
13
|
def initialize(options)
|
9
14
|
Validation.validate_options options
|
10
|
-
@options =
|
15
|
+
@options = options.transform_values(&:to_a)
|
11
16
|
|
12
17
|
# End to start is more traditional way of making combinations.
|
13
18
|
@keys = @options.keys.reverse
|
@@ -20,7 +25,7 @@ class OCG
|
|
20
25
|
end
|
21
26
|
|
22
27
|
protected def reset_value_indexes
|
23
|
-
@value_indexes =
|
28
|
+
@value_indexes = @options.transform_values { |_values| 0 }
|
24
29
|
end
|
25
30
|
|
26
31
|
def reset
|
data/lib/ocg/version.rb
CHANGED
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.
|
4
|
+
version: 1.3.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: 2020-
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '5.
|
33
|
+
version: '5.14'
|
34
34
|
type: :development
|
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: '5.
|
40
|
+
version: '5.14'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.1'
|
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: '
|
68
|
+
version: '1.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop-performance
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.8'
|
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.
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rails
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '2.3'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '2.3'
|
82
|
+
version: '1.8'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: simplecov
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +104,7 @@ files:
|
|
118
104
|
- LICENSE
|
119
105
|
- README.md
|
120
106
|
- lib/ocg.rb
|
107
|
+
- lib/ocg/copyable.rb
|
121
108
|
- lib/ocg/error.rb
|
122
109
|
- lib/ocg/main.rb
|
123
110
|
- lib/ocg/operator/abstract.rb
|
@@ -139,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
126
|
requirements:
|
140
127
|
- - ">="
|
141
128
|
- !ruby/object:Gem::Version
|
142
|
-
version: '
|
129
|
+
version: '2.5'
|
143
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
131
|
requirements:
|
145
132
|
- - ">="
|
146
133
|
- !ruby/object:Gem::Version
|
147
134
|
version: '0'
|
148
135
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.1.4
|
150
137
|
signing_key:
|
151
138
|
specification_version: 4
|
152
139
|
summary: Option combination generator.
|