ocg 1.1.3 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -32
- 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 +5 -0
- data/lib/ocg/version.rb +1 -1
- metadata +32 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f1bbd2f95185a3f9098a0e861afbcdc5372126c0956adc4b32547c26a22dc35
|
4
|
+
data.tar.gz: 79c9230bcca50efb4cebd233dc16f68e7ac871499c8ce7e519557e56e5cb17cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff79d40bcf1a14c77809a4c8662aae70c5d597aa5c7be693fa337ea06bf826704ac1ef7ba27177620337cba8bf9b966752ba836e07d5276c798db17c3cee5e8
|
7
|
+
data.tar.gz: 8ef828c80ddc4709b0c7030876f2a06a30954662d8397c06afdb7fc313d93f4283a81664db4bf73d56bdee315ff713d74fe015a15829619e03f41f501a660153
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Option combination generator
|
2
2
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
| [![
|
3
|
+
| AppVeyor | Circle | Github Actions | Codecov | Gem |
|
4
|
+
| :------: | :----: | :------------: | :-----: | :-: |
|
5
|
+
| [![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) | [![Github Actions test status](https://github.com/andrew-aladev/ocg/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ocg/actions) | [![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-3.0.0/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.
|
@@ -157,14 +159,16 @@ complete_generator = almost_complete_generator.mix(
|
|
157
159
|
)
|
158
160
|
```
|
159
161
|
|
162
|
+
## Operating systems
|
163
|
+
|
164
|
+
GNU/Linux, FreeBSD, OSX, Windows (MinGW).
|
165
|
+
|
160
166
|
## CI
|
161
167
|
|
162
|
-
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
163
168
|
Please visit [scripts/test-images](scripts/test-images).
|
164
|
-
|
165
|
-
|
166
|
-
Cirrus CI uses `x86_64-pc-linux-gnu` image, Circle CI - `x86_64-gentoo-linux-musl` image.
|
169
|
+
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.
|
167
171
|
|
168
172
|
## License
|
169
173
|
|
170
|
-
MIT license, see LICENSE and AUTHORS.
|
174
|
+
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,10 +1,15 @@
|
|
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
15
|
@options = options.transform_values(&:to_a)
|
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.1
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-29 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,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.8'
|
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.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop-performance
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
89
|
+
version: '1.9'
|
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: '1.
|
96
|
+
version: '1.9'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-
|
98
|
+
name: rubocop-rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '0.5'
|
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: '
|
110
|
+
version: '0.5'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: simplecov
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +122,7 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
|
-
description:
|
125
|
+
description:
|
112
126
|
email: aladjev.andrew@gmail.com
|
113
127
|
executables: []
|
114
128
|
extensions: []
|
@@ -118,6 +132,7 @@ files:
|
|
118
132
|
- LICENSE
|
119
133
|
- README.md
|
120
134
|
- lib/ocg.rb
|
135
|
+
- lib/ocg/copyable.rb
|
121
136
|
- lib/ocg/error.rb
|
122
137
|
- lib/ocg/main.rb
|
123
138
|
- lib/ocg/operator/abstract.rb
|
@@ -131,7 +146,7 @@ homepage: https://github.com/andrew-aladev/ocg
|
|
131
146
|
licenses:
|
132
147
|
- MIT
|
133
148
|
metadata: {}
|
134
|
-
post_install_message:
|
149
|
+
post_install_message:
|
135
150
|
rdoc_options: []
|
136
151
|
require_paths:
|
137
152
|
- lib
|
@@ -139,15 +154,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
154
|
requirements:
|
140
155
|
- - ">="
|
141
156
|
- !ruby/object:Gem::Version
|
142
|
-
version: '
|
157
|
+
version: '2.5'
|
143
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
159
|
requirements:
|
145
160
|
- - ">="
|
146
161
|
- !ruby/object:Gem::Version
|
147
162
|
version: '0'
|
148
163
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
150
|
-
signing_key:
|
164
|
+
rubygems_version: 3.2.3
|
165
|
+
signing_key:
|
151
166
|
specification_version: 4
|
152
167
|
summary: Option combination generator.
|
153
168
|
test_files: []
|