merginator 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +52 -3
- data/README.md +3 -3
- data/Rakefile +17 -1
- data/Steepfile +5 -0
- data/lib/merginator/pattern_merge.rb +45 -18
- data/lib/merginator/version.rb +1 -1
- data/lib/merginator.rb +0 -2
- data/merginator.gemspec +38 -0
- data/rbs_collection.lock.yaml +18 -0
- data/rbs_collection.yaml +20 -0
- data/sig/mergifier/pattern_merge.rbs +15 -6
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d45708d09006490c77f0d2819b0fecc13e35a2a81e69a6f4c7fcf5c8a8bf7f
|
4
|
+
data.tar.gz: c508d5dec15b52a26e3388130d9845a20b4821a1fb5f3f8c7acf735e48afc770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c85058dd8a0282a43ce46050c4ddba76c9d7f7bb6a2997f2bdf06bf10646f1797e4f1f13a98bd1ec740449dd6501c8b5990255e19d8e5b08eba7e6bc68e0aa81
|
7
|
+
data.tar.gz: a4365f144da7520eecc9e18080aabe6cf16a3322778a5c08a7ff06832d6b85aa0e204629b667cd673d879f0244849da005b706e437897ddf266054c3bc92e13b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -8,8 +8,8 @@ gemspec
|
|
8
8
|
gem 'rake'
|
9
9
|
|
10
10
|
gem 'minitest'
|
11
|
-
|
12
|
-
gem 'rubocop'
|
11
|
+
gem 'rubocop', require: false
|
13
12
|
gem 'rubocop-minitest', require: false
|
14
13
|
gem 'rubocop-rake', require: false
|
15
|
-
gem '
|
14
|
+
gem 'simplecov', require: false
|
15
|
+
gem 'steep', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
merginator (0.
|
4
|
+
merginator (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
activesupport (7.0.5.1)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
9
14
|
ast (2.4.2)
|
15
|
+
concurrent-ruby (1.2.2)
|
16
|
+
csv (3.2.7)
|
17
|
+
docile (1.3.5)
|
18
|
+
ffi (1.15.5)
|
19
|
+
fileutils (1.7.1)
|
20
|
+
i18n (1.14.1)
|
21
|
+
concurrent-ruby (~> 1.0)
|
10
22
|
json (2.6.3)
|
23
|
+
language_server-protocol (3.17.0.3)
|
24
|
+
listen (3.8.0)
|
25
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
26
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
27
|
+
logger (1.5.3)
|
11
28
|
minitest (5.18.1)
|
12
29
|
parallel (1.23.0)
|
13
30
|
parser (3.2.2.3)
|
@@ -16,11 +33,15 @@ GEM
|
|
16
33
|
racc (1.7.1)
|
17
34
|
rainbow (3.1.1)
|
18
35
|
rake (13.0.6)
|
36
|
+
rb-fsevent (0.11.2)
|
37
|
+
rb-inotify (0.10.1)
|
38
|
+
ffi (~> 1.0)
|
19
39
|
rbs (3.1.0)
|
20
40
|
regexp_parser (2.8.1)
|
21
41
|
rexml (3.2.5)
|
22
|
-
rubocop (1.
|
42
|
+
rubocop (1.53.1)
|
23
43
|
json (~> 2.3)
|
44
|
+
language_server-protocol (>= 3.17.0)
|
24
45
|
parallel (~> 1.10)
|
25
46
|
parser (>= 3.2.2.3)
|
26
47
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -36,6 +57,33 @@ GEM
|
|
36
57
|
rubocop-rake (0.6.0)
|
37
58
|
rubocop (~> 1.0)
|
38
59
|
ruby-progressbar (1.13.0)
|
60
|
+
securerandom (0.2.2)
|
61
|
+
simplecov (0.21.2)
|
62
|
+
docile (~> 1.1)
|
63
|
+
simplecov-html (~> 0.11)
|
64
|
+
simplecov_json_formatter (~> 0.1)
|
65
|
+
simplecov-html (0.12.3)
|
66
|
+
simplecov_json_formatter (0.1.2)
|
67
|
+
steep (1.4.0)
|
68
|
+
activesupport (>= 5.1)
|
69
|
+
concurrent-ruby (>= 1.2.2)
|
70
|
+
csv (>= 3.0.9)
|
71
|
+
fileutils (>= 1.1.0)
|
72
|
+
json (>= 2.1.0)
|
73
|
+
language_server-protocol (>= 3.15, < 4.0)
|
74
|
+
listen (~> 3.0)
|
75
|
+
logger (>= 1.3.0)
|
76
|
+
parser (>= 3.1)
|
77
|
+
rainbow (>= 2.2.2, < 4.0)
|
78
|
+
rbs (>= 2.8.0)
|
79
|
+
securerandom (>= 0.1)
|
80
|
+
strscan (>= 1.0.0)
|
81
|
+
terminal-table (>= 2, < 4)
|
82
|
+
strscan (3.0.6)
|
83
|
+
terminal-table (3.0.2)
|
84
|
+
unicode-display_width (>= 1.1.1, < 3)
|
85
|
+
tzinfo (2.0.6)
|
86
|
+
concurrent-ruby (~> 1.0)
|
39
87
|
unicode-display_width (2.4.2)
|
40
88
|
|
41
89
|
PLATFORMS
|
@@ -45,10 +93,11 @@ DEPENDENCIES
|
|
45
93
|
merginator!
|
46
94
|
minitest
|
47
95
|
rake
|
48
|
-
rbs
|
49
96
|
rubocop
|
50
97
|
rubocop-minitest
|
51
98
|
rubocop-rake
|
99
|
+
simplecov
|
100
|
+
steep
|
52
101
|
|
53
102
|
BUNDLED WITH
|
54
103
|
2.1.4
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Merginator
|
1
|
+
# Merginator [](https://badge.fury.io/rb/merginator) 
|
2
2
|
|
3
3
|
Easily merge collections with a simple API!
|
4
4
|
|
@@ -6,11 +6,11 @@ Easily merge collections with a simple API!
|
|
6
6
|
|
7
7
|
Install the gem and add to the application's Gemfile by executing:
|
8
8
|
|
9
|
-
$ bundle add
|
9
|
+
$ bundle add merginator
|
10
10
|
|
11
11
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
12
|
|
13
|
-
$ gem install
|
13
|
+
$ gem install merginator
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
data/Rakefile
CHANGED
@@ -13,4 +13,20 @@ require 'rubocop/rake_task'
|
|
13
13
|
|
14
14
|
RuboCop::RakeTask.new
|
15
15
|
|
16
|
-
|
16
|
+
namespace :test do
|
17
|
+
desc 'Run all tests: tests, rubocop, and steep'
|
18
|
+
task :all do
|
19
|
+
Rake::Task['test'].execute
|
20
|
+
Rake::Task['rubocop'].execute
|
21
|
+
Rake::Task['test:steep:check'].execute
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :steep do
|
25
|
+
desc 'Run steep check'
|
26
|
+
task :check do
|
27
|
+
sh 'steep', 'check'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: %i[test rubocop test:steep:check]
|
data/Steepfile
ADDED
@@ -7,33 +7,34 @@ module Merginator
|
|
7
7
|
# first, 2 from the second, and one from the third. Also passing in the total,
|
8
8
|
# or, an amount for a page
|
9
9
|
class PatternMerge
|
10
|
-
attr_reader :pattern, :total, :counts
|
10
|
+
attr_reader :pattern, :total, :counts, :wrapper
|
11
11
|
|
12
|
-
def initialize(*pattern, total: nil)
|
12
|
+
def initialize(*pattern, total: nil, wrapper: [])
|
13
13
|
@pattern = pattern
|
14
14
|
validate_pattern
|
15
15
|
|
16
16
|
@total = total
|
17
17
|
validate_total
|
18
18
|
|
19
|
+
@wrapper = wrapper
|
20
|
+
validate_wrapper
|
21
|
+
|
19
22
|
# Counts are helpful when you're looking for a particular length end result
|
20
23
|
# and querying a database or index. If you're not, they're not needed.
|
21
|
-
@counts = generate_pattern_counts(@total)
|
24
|
+
@counts = generate_pattern_counts(@total)
|
22
25
|
end
|
23
26
|
|
24
|
-
def merge(*collections)
|
27
|
+
def merge(*collections, wrapper: @wrapper, ignore_total: false)
|
25
28
|
validate_merge_collections(collections)
|
29
|
+
validate_wrapper wrapper
|
26
30
|
|
27
|
-
|
31
|
+
total_to_use = @total
|
32
|
+
total_to_use = collections.sum(&:size) if !total || ignore_total
|
28
33
|
|
29
|
-
slices_for_collections = collections
|
30
|
-
|
31
|
-
end
|
34
|
+
slices_for_collections = slice_collections(collections)
|
35
|
+
merge_collections_into_wrapper(slices_for_collections, wrapper: wrapper, total: total_to_use)
|
32
36
|
|
33
|
-
|
34
|
-
arr << slices_for_collections.map { |slices| slices[index] || [] }.flatten
|
35
|
-
break(arr) if arr.flatten.size >= total
|
36
|
-
end.flatten.take(total)
|
37
|
+
wrapper
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
@@ -44,6 +45,8 @@ module Merginator
|
|
44
45
|
# Merginator::Mergifier::PatternMerge.new(4, 2, 1, total: 25)
|
45
46
|
# => [16, 6, 3]
|
46
47
|
def generate_pattern_counts(total)
|
48
|
+
return unless total
|
49
|
+
|
47
50
|
full_repetitions = total / @pattern.sum
|
48
51
|
counts = @pattern.map { |num| num * full_repetitions }
|
49
52
|
|
@@ -57,13 +60,30 @@ module Merginator
|
|
57
60
|
counts
|
58
61
|
end
|
59
62
|
|
63
|
+
def slice_collections(collections)
|
64
|
+
collections.map.with_index do |collection, index|
|
65
|
+
collection.each_slice(@pattern[index]).to_a
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def merge_collections_into_wrapper(slices_for_collections, wrapper:, total:)
|
70
|
+
slices_for_collections.map(&:size).max.to_i.times.each_with_object(wrapper) do |index, wrapper_obj|
|
71
|
+
wrapper_obj.concat slices_for_collections.map { |slices| slices[index] || [] }.flatten
|
72
|
+
break(wrapper_obj) if wrapper_obj.size >= total
|
73
|
+
end
|
74
|
+
|
75
|
+
wrapper.replace wrapper.take(total)
|
76
|
+
end
|
77
|
+
|
60
78
|
def validate_pattern
|
61
79
|
raise ArgumentError, 'there must be more than one collection in the pattern' if @pattern.count <= 1
|
62
80
|
raise ArgumentError, 'pattern must be all integers' unless @pattern.all? { |n| n.is_a? Integer }
|
63
81
|
end
|
64
82
|
|
65
83
|
def validate_total
|
66
|
-
|
84
|
+
return if (@total || 1).positive?
|
85
|
+
|
86
|
+
raise ArgumentError, 'total must be at least 1'
|
67
87
|
end
|
68
88
|
|
69
89
|
def validate_merge_collections(collections)
|
@@ -73,11 +93,18 @@ module Merginator
|
|
73
93
|
raise ArgumentError, message
|
74
94
|
end
|
75
95
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
96
|
+
total_to_use = @total || collections.flatten.count
|
97
|
+
return if collections.flatten.count >= total_to_use
|
98
|
+
|
99
|
+
message = 'total number of elements in collections must be >= provided total; '
|
100
|
+
message += "expected #{@total} elements, actual: #{collections.flatten.count}"
|
101
|
+
raise ArgumentError, message
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_wrapper(wrapper = @wrapper)
|
105
|
+
return if wrapper.is_a?(Array)
|
106
|
+
|
107
|
+
raise ArgumentError, 'wrapper must be like an array'
|
81
108
|
end
|
82
109
|
end
|
83
110
|
end
|
data/lib/merginator/version.rb
CHANGED
data/lib/merginator.rb
CHANGED
data/merginator.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/merginator/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'merginator'
|
7
|
+
spec.version = Merginator::VERSION
|
8
|
+
spec.authors = ['Ryan Verhey']
|
9
|
+
spec.email = ['ryan@ryanverhey.com']
|
10
|
+
|
11
|
+
spec.summary = 'Merging collections based on a pattern.'
|
12
|
+
spec.description = 'Merge 2 or more collections based on a repeating pattern.'
|
13
|
+
spec.homepage = 'https://github.com/RyanVerhey/merginator'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.7.8'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/RyanVerhey/merginator'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/RyanVerhey/merginator/blob/main/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, check out our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
|
6
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
7
|
+
repo_dir: gems
|
8
|
+
path: ".gem_rbs_collection"
|
9
|
+
gems:
|
10
|
+
- name: minitest
|
11
|
+
version: '0'
|
12
|
+
source:
|
13
|
+
type: stdlib
|
14
|
+
- name: mutex_m
|
15
|
+
version: '0'
|
16
|
+
source:
|
17
|
+
type: stdlib
|
18
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
gems:
|
17
|
+
# Skip loading rbs gem's RBS.
|
18
|
+
# It's unnecessary if you don't use rbs as a library.
|
19
|
+
- name: rbs
|
20
|
+
ignore: true
|
@@ -1,15 +1,24 @@
|
|
1
1
|
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
2
|
+
type wrapper = Array[untyped]
|
3
|
+
type collection = Array[untyped]
|
4
|
+
type total = Integer?
|
5
|
+
|
2
6
|
class Merginator::PatternMerge
|
3
|
-
|
4
|
-
|
5
|
-
|
7
|
+
attr_reader pattern: Array[Integer]
|
8
|
+
attr_reader total: total
|
9
|
+
attr_reader counts: Array[Integer]?
|
10
|
+
attr_reader wrapper: wrapper
|
6
11
|
|
7
|
-
def
|
12
|
+
def initialize: (*Integer, ?total: total, ?wrapper: wrapper) -> void
|
13
|
+
def merge: (*collection, ?wrapper: wrapper, ?ignore_total: bool) -> wrapper
|
8
14
|
|
9
15
|
private
|
10
16
|
|
11
|
-
def generate_pattern_counts: (
|
17
|
+
def generate_pattern_counts: (total) -> Array[Integer]?
|
18
|
+
def slice_collections: (Array[collection]) -> Array[Array[untyped]]
|
19
|
+
def merge_collections_into_wrapper: (Array[Array[untyped]], wrapper: wrapper, total: Integer) -> wrapper
|
12
20
|
def validate_pattern: () -> void
|
13
21
|
def validate_total: () -> void
|
14
|
-
def validate_merge_collections: (
|
22
|
+
def validate_merge_collections: (Array[collection]) -> void
|
23
|
+
def validate_wrapper: (?wrapper) -> void
|
15
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merginator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Verhey
|
@@ -26,9 +26,13 @@ files:
|
|
26
26
|
- LICENSE.txt
|
27
27
|
- README.md
|
28
28
|
- Rakefile
|
29
|
+
- Steepfile
|
29
30
|
- lib/merginator.rb
|
30
31
|
- lib/merginator/pattern_merge.rb
|
31
32
|
- lib/merginator/version.rb
|
33
|
+
- merginator.gemspec
|
34
|
+
- rbs_collection.lock.yaml
|
35
|
+
- rbs_collection.yaml
|
32
36
|
- sig/mergifier/pattern_merge.rbs
|
33
37
|
- sig/merginator.rbs
|
34
38
|
homepage: https://github.com/RyanVerhey/merginator
|