ocg 1.2.0 → 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 +5 -0
- data/lib/ocg/copyable.rb +17 -0
- data/lib/ocg/main.rb +9 -7
- data/lib/ocg/operator/abstract.rb +2 -0
- data/lib/ocg/operator/mix.rb +10 -0
- data/lib/ocg/options.rb +5 -0
- data/lib/ocg/version.rb +1 -1
- metadata +5 -4
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
@@ -62,8 +62,13 @@ It will provide all possible option combinations.
|
|
62
62
|
| `started?` | returns true when at least one combination was generated |
|
63
63
|
| `finished?` | returns true when all combination were generated |
|
64
64
|
| `length` | returns combinations length |
|
65
|
+
| `dup` | returns generator duplicate |
|
66
|
+
| `clone` | returns generator clone |
|
65
67
|
|
66
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
|
+
|
67
72
|
You can combine generators using `and`, `mix` and `or`.
|
68
73
|
|
69
74
|
Options should be prepared in the following form:
|
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,14 +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
|
10
12
|
include ::Enumerable
|
11
13
|
extend ::Forwardable
|
12
14
|
|
13
|
-
DELEGATORS
|
15
|
+
DELEGATORS = %i[reset next last started? finished? length].freeze
|
16
|
+
VARIABLES_TO_COPY = %i[generator].freeze
|
17
|
+
|
18
|
+
def_delegators :@generator, *DELEGATORS
|
14
19
|
|
15
20
|
def initialize(generator_or_options)
|
16
21
|
@generator = self.class.prepare_generator generator_or_options
|
@@ -22,8 +27,6 @@ class OCG
|
|
22
27
|
Options.new generator_or_options
|
23
28
|
end
|
24
29
|
|
25
|
-
def_delegators :@generator, *DELEGATORS
|
26
|
-
|
27
30
|
def and(generator_or_options)
|
28
31
|
Operator::AND.new self, generator_or_options
|
29
32
|
end
|
@@ -37,11 +40,10 @@ class OCG
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def each(&_block)
|
40
|
-
|
41
|
-
|
42
|
-
yield send("next") until finished?
|
43
|
+
instance = dup
|
44
|
+
instance.reset
|
43
45
|
|
44
|
-
|
46
|
+
yield instance.next until instance.finished?
|
45
47
|
|
46
48
|
nil
|
47
49
|
end
|
@@ -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)
|
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-
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -58,14 +58,14 @@ 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
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- LICENSE
|
105
105
|
- README.md
|
106
106
|
- lib/ocg.rb
|
107
|
+
- lib/ocg/copyable.rb
|
107
108
|
- lib/ocg/error.rb
|
108
109
|
- lib/ocg/main.rb
|
109
110
|
- lib/ocg/operator/abstract.rb
|