ocg 1.1.5 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -8
- data/lib/ocg/copyable.rb +17 -0
- data/lib/ocg/main.rb +12 -10
- data/lib/ocg/operator/abstract.rb +2 -0
- data/lib/ocg/operator/mix.rb +10 -0
- data/lib/ocg/options.rb +6 -1
- data/lib/ocg/version.rb +1 -1
- metadata +56 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3317ee152e34d25859c9e33881c0d2f06f98ab93f94b5cc53ecbbef5906094
|
4
|
+
data.tar.gz: a017104ff2892aa0cc64a883fa968ea2ed951783f8ea202d60d9e2b2fb73f630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e506b9897a3bf5d8c7aac31ff4cb5777ab919b6f386355615f80914b7a90406ace7e0bbcf37db294775cabcf655e0ea856b9c0ab30a4af51622378be874709
|
7
|
+
data.tar.gz: 8c39eb233a8bda10be52b52c696d66284ced715454eb06890b10730d77319633c52145a750a1c726c21f544445c37c62aa764b84bd5615f0eb5252381f1015f9
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
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
|
|
9
|
+
Operating systems: GNU/Linux, OSX, FreeBSD, Windows.
|
10
|
+
|
9
11
|
```sh
|
10
12
|
gem install ocg
|
11
13
|
```
|
@@ -41,7 +43,7 @@ generator = OCG.new(
|
|
41
43
|
:h => 7..8
|
42
44
|
)
|
43
45
|
|
44
|
-
|
46
|
+
generator.each { |combination| puts combination }
|
45
47
|
```
|
46
48
|
|
47
49
|
It will populate all option combinations.
|
@@ -62,7 +64,12 @@ It will provide all possible option combinations.
|
|
62
64
|
| `started?` | returns true when at least one combination was generated |
|
63
65
|
| `finished?` | returns true when all combination were generated |
|
64
66
|
| `length` | returns combinations length |
|
65
|
-
| `
|
67
|
+
| `dup` | returns generator duplicate |
|
68
|
+
| `clone` | returns generator clone |
|
69
|
+
|
70
|
+
Generator is responsible to any method from [`Enumerable`](https://ruby-doc.org/core-3.0.1/Enumerable.html).
|
71
|
+
Enumerator will be provided using generator duplicate.
|
72
|
+
So enumerable api is separated from bare metal api (`reset`, `next`, `last`, `started?`, `finished?`).
|
66
73
|
|
67
74
|
You can combine generators using `and`, `mix` and `or`.
|
68
75
|
|
@@ -156,10 +163,9 @@ complete_generator = almost_complete_generator.mix(
|
|
156
163
|
|
157
164
|
## CI
|
158
165
|
|
159
|
-
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
160
166
|
Please visit [scripts/test-images](scripts/test-images).
|
161
|
-
|
167
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
162
168
|
|
163
169
|
## License
|
164
170
|
|
165
|
-
MIT license, see LICENSE and AUTHORS.
|
171
|
+
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,6 +6,8 @@ require_relative "../error"
|
|
6
6
|
class OCG
|
7
7
|
module Operator
|
8
8
|
class Abstract < OCG
|
9
|
+
VARIABLES_TO_COPY = %i[left_generator right_generator].freeze
|
10
|
+
|
9
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
|
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)
|
@@ -39,7 +44,7 @@ class OCG
|
|
39
44
|
def next
|
40
45
|
return nil if @is_finished
|
41
46
|
|
42
|
-
@last_options =
|
47
|
+
@last_options = @value_indexes.map { |name, value_index| [name, @options[name][value_index]] }.to_h
|
43
48
|
|
44
49
|
@is_finished = @keys.all? do |name|
|
45
50
|
values = @options[name]
|
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.3
|
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-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -24,20 +24,34 @@ 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
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '5.
|
47
|
+
version: '5.14'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '5.
|
54
|
+
version: '5.14'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +72,56 @@ dependencies:
|
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '1.16'
|
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: '
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.12'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rubocop-performance
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
103
|
+
version: '1.11'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.11'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.5'
|
76
118
|
type: :development
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
122
|
- - "~>"
|
81
123
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
124
|
+
version: '0.5'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: simplecov
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +136,7 @@ dependencies:
|
|
94
136
|
- - ">="
|
95
137
|
- !ruby/object:Gem::Version
|
96
138
|
version: '0'
|
97
|
-
description:
|
139
|
+
description:
|
98
140
|
email: aladjev.andrew@gmail.com
|
99
141
|
executables: []
|
100
142
|
extensions: []
|
@@ -104,6 +146,7 @@ files:
|
|
104
146
|
- LICENSE
|
105
147
|
- README.md
|
106
148
|
- lib/ocg.rb
|
149
|
+
- lib/ocg/copyable.rb
|
107
150
|
- lib/ocg/error.rb
|
108
151
|
- lib/ocg/main.rb
|
109
152
|
- lib/ocg/operator/abstract.rb
|
@@ -117,7 +160,7 @@ homepage: https://github.com/andrew-aladev/ocg
|
|
117
160
|
licenses:
|
118
161
|
- MIT
|
119
162
|
metadata: {}
|
120
|
-
post_install_message:
|
163
|
+
post_install_message:
|
121
164
|
rdoc_options: []
|
122
165
|
require_paths:
|
123
166
|
- lib
|
@@ -132,8 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
175
|
- !ruby/object:Gem::Version
|
133
176
|
version: '0'
|
134
177
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
178
|
+
rubygems_version: 3.2.15
|
179
|
+
signing_key:
|
137
180
|
specification_version: 4
|
138
181
|
summary: Option combination generator.
|
139
182
|
test_files: []
|