ocg 1.1.4 → 1.3.2

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: 59aa6a751c46f2c5df99170cbc90b6d588a31cd6c58c0c1442405545346196e6
4
- data.tar.gz: 51ad926c4f636f950e478537d68694743997d5edbc510d801163666819dc18b0
3
+ metadata.gz: e1d6d020cfd6918a3911fdbdf27adf4a188e9fe643f43cadb2ff9132b8419d47
4
+ data.tar.gz: aa8b3b23e632a29ffdc103c0292e77e91ee79c4e64979c7c0e73e252864ce1ed
5
5
  SHA512:
6
- metadata.gz: 0e369db994e082505ac85c156a0c92801e14a148ee1c139be7a9edf7834cb6bbcf13534638d33ebb848de8edb455afca054ac8efe21f5b1882f54238f3a379cb
7
- data.tar.gz: '0729c7969f7d29adf70a3ef0a03ba65f4cb2b11092cafc8e963532d82f145b9f61a466a9e622ba57e573272ec1c138bd6ca0155c13ff083b1aac04ccd6f7e29a'
6
+ metadata.gz: 2988e11f4f3576c5cd648832f29256fb6cfc705301954c7b000d61fde7dc343b7f3f99dd6dcc8281191cabf87e8dcc42f7cae3ed1153907f510fdb4ef535450d
7
+ data.tar.gz: b1093946df6b54282fcc4c7019c20f453042880068862e0a9fc682033b28b1385b503d1f08f388f44c8119a201ea573f3a54c217b34b1bd89275d8e468981a9e
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Option combination generator
2
2
 
3
- | Travis | AppVeyor | Circle | Codecov |
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) |
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
- puts generator.next until generator.finished?
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
- | `to_a` | returns combinations array |
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
- You can run this test script using many native and cross images.
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).
@@ -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 = %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
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 to_a
39
- reset
40
-
41
- result = []
42
- result << send("next") until finished?
42
+ def each(&_block)
43
+ instance = dup
44
+ instance.reset
43
45
 
44
- reset
46
+ yield instance.next until instance.finished?
45
47
 
46
- result
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
@@ -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 = Hash[@value_indexes.map { |name, value_index| [name, @options[name][value_index]] }]
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
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  class OCG
5
- VERSION = "1.1.4".freeze
5
+ VERSION = "1.3.2".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.1.4
4
+ version: 1.3.2
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: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2021-05-11 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.12'
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.12'
40
+ version: '5.14'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,56 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.75'
61
+ version: '1.14'
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.75'
68
+ version: '1.14'
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.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
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.5'
89
+ version: '1.11'
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.5'
96
+ version: '1.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.5'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: simplecov
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +122,7 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
- description:
125
+ description:
98
126
  email: aladjev.andrew@gmail.com
99
127
  executables: []
100
128
  extensions: []
@@ -104,6 +132,7 @@ files:
104
132
  - LICENSE
105
133
  - README.md
106
134
  - lib/ocg.rb
135
+ - lib/ocg/copyable.rb
107
136
  - lib/ocg/error.rb
108
137
  - lib/ocg/main.rb
109
138
  - lib/ocg/operator/abstract.rb
@@ -117,23 +146,23 @@ homepage: https://github.com/andrew-aladev/ocg
117
146
  licenses:
118
147
  - MIT
119
148
  metadata: {}
120
- post_install_message:
149
+ post_install_message:
121
150
  rdoc_options: []
122
151
  require_paths:
123
152
  - lib
124
153
  required_ruby_version: !ruby/object:Gem::Requirement
125
154
  requirements:
126
- - - "~>"
155
+ - - ">="
127
156
  - !ruby/object:Gem::Version
128
- version: '2.7'
157
+ version: '2.5'
129
158
  required_rubygems_version: !ruby/object:Gem::Requirement
130
159
  requirements:
131
160
  - - ">="
132
161
  - !ruby/object:Gem::Version
133
162
  version: '0'
134
163
  requirements: []
135
- rubygems_version: 3.1.2
136
- signing_key:
164
+ rubygems_version: 3.2.15
165
+ signing_key:
137
166
  specification_version: 4
138
167
  summary: Option combination generator.
139
168
  test_files: []