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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b0c6aa85ed30a2ae8c65d872e90136d223822fc8d970c26c6515f56ee84b98
4
- data.tar.gz: 248d46514c8fba336fef0347f5d21d40752651cfc4b3846110e69480f8da02a2
3
+ metadata.gz: a3e653800a9ddc59e36ee81e45dd0a85b3e0120418c2155aa4d4a1a4b659d949
4
+ data.tar.gz: 3f22c5f598564d3c57844e8048258795b8868763912322b156e079ce966464b9
5
5
  SHA512:
6
- metadata.gz: 15fb346aa655fe3cf505439073ccdd8156c1b341b5ddd38ef4ce7a7e89e4982f2c5ebad4e43ebe3bde8172bd2c46776d9a154db37b2acab94bdcd088df5afb69
7
- data.tar.gz: 4ff7e04a1684f0c073f0366360d1145e0bdaf9323a6d03ff2c828756bf88c53ecf7eae79b2055f3ccce5605c558b09d6804202d1cdc29d1d069e8b1adc0199f2
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:
@@ -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
@@ -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 = %i[reset next last started? finished? length].freeze
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
- reset
41
-
42
- yield send("next") until finished?
43
+ instance = dup
44
+ instance.reset
43
45
 
44
- reset
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
@@ -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
@@ -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)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
- VERSION = "1.2.0".freeze
5
+ VERSION = "1.3.0".freeze
6
6
  end
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.2.0
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-03 00:00:00.000000000 Z
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: '0.93'
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: '0.93'
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