sequel-batches 1.0.1 → 1.1.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: 75f26b2a799694f8ab7c27d9b2e9fdbf12990d92c3c9a5ba2117ec9c7815cb47
4
- data.tar.gz: be0eb9ffc65170761b2000c20c2c8e628c8eacc2cfbf1cee7d4fbf54c0134760
3
+ metadata.gz: 2ba86551c2e6fa28e3c012fec381ca293267b3c04629f8295114724a2c7ff99a
4
+ data.tar.gz: c36a543672f8d6869e4189ad808ac15c275d0342cc41ec3a258a0299e4225829
5
5
  SHA512:
6
- metadata.gz: 874d85e620b0d5cbe2a82700deff251edf004bca67a64e89ece8fca769abcbc5f117891d02767f0873634156de7680558cfeceee0abd917f7a762c8f5720c42c
7
- data.tar.gz: 39ca7cd7e363ab3fe6d8d04ef7c73f140369f3e0e6a87c8d79605d6c80882c2bcbc0fb625ee8dccc8d297f20d5516c031b126c82cbcc38f3d291474ccbe226be
6
+ metadata.gz: 655a16e69b97c23fe80c92beef06e5cc80fa242b161955ef3702193385528b67b8575a14c5b75ed0e7cc4af559e1a04e0e0141e8ab4ef60c5cfc350ac5afda9c
7
+ data.tar.gz: c36d801caaf7cefc37520c4db12ce9d47ff62c20eb2c9c8c2c9813775829bd5acbaa0bc8f1d6953b5fc1c6dfbcea34650eec29ca37f8c15731872bd1915f193a
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on: [pull_request, push]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/sequel-batches'
10
+
11
+ services:
12
+ postgres:
13
+ image: postgres
14
+ env:
15
+ POSTGRES_USER: root
16
+ POSTGRES_HOST_AUTH_METHOD: trust
17
+ options: >-
18
+ --health-cmd pg_isready
19
+ --health-interval 10s
20
+ --health-timeout 5s
21
+ --health-retries 5
22
+ ports:
23
+ - 5432:5432
24
+
25
+ env:
26
+ PGHOST: localhost
27
+ PGUSER: root
28
+
29
+ strategy:
30
+ fail-fast: false
31
+ matrix:
32
+ ruby: [2.6, 2.7, "3.0", jruby-9.3.1.0, ruby-head, jruby-head]
33
+
34
+ name: ${{ matrix.ruby }}
35
+
36
+ steps:
37
+ - uses: actions/checkout@v2
38
+ - uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.ruby }}
41
+ bundler-cache: true
42
+
43
+ - run: psql -c 'CREATE DATABASE batches_test'
44
+ - run: bundle exec rake bundle:audit
45
+ - run: bundle exec rake lint
46
+ - run: bundle exec rspec
47
+ continue-on-error: ${{ matrix.ruby == 'jruby-head' || matrix.ruby == 'ruby-head' }}
48
+
49
+ - uses: coverallsapp/github-action@v1.1.2
50
+ with:
51
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/.rubocop.yml CHANGED
@@ -3,7 +3,16 @@ inherit_gem:
3
3
 
4
4
  AllCops:
5
5
  DisplayCopNames: true
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.6
7
+ Include:
8
+ - lib/**/*.rb
9
+ - spec/**/*.rb
10
+ - Gemfile
11
+ - Rakefile
12
+ - sequel-batches.gemspec
13
+
14
+ Layout/LineLength:
15
+ Max: 120
7
16
 
8
17
  Naming/MethodParameterName:
9
18
  Enabled: false
data/README.md CHANGED
@@ -44,6 +44,7 @@ options = {
44
44
  pk: [:project_id, :external_user_id],
45
45
  start: { project_id: 2, external_user_id: 3 },
46
46
  finish: { project_id: 5, external_user_id: 70 },
47
+ order: :desc,
47
48
  }
48
49
 
49
50
  Event.where(type: "login").in_batches(options) do |ds|
@@ -69,6 +70,9 @@ A hash `{ [column]: <start_value> }` that represents frame start for batch proce
69
70
  ### finish
70
71
  Same as `start` but represents the frame end.
71
72
 
73
+ ### order
74
+ Specifies the primary key order (can be :asc or :desc). Defaults to :asc.
75
+
72
76
  ## Contributing
73
77
 
74
78
  Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/sequel-batches.
data/Rakefile CHANGED
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "bundler/audit/task"
4
5
  require "rspec/core/rake_task"
5
6
  require "rubocop/rake_task"
6
7
 
7
8
  RSpec::Core::RakeTask.new(:spec)
8
- RuboCop::RakeTask.new(:lint)
9
+ RuboCop::RakeTask.new(:lint) do |t|
10
+ config_path = File.expand_path(File.join(".rubocop.yml"), __dir__)
11
+
12
+ t.options = ["--config", config_path]
13
+ t.requires << "rubocop-rspec"
14
+ t.requires << "rubocop-performance"
15
+ end
16
+ Bundler::Audit::Task.new
9
17
 
10
18
  task default: %i[lint spec]
@@ -2,33 +2,38 @@
2
2
 
3
3
  module Sequel::Extensions::Batches
4
4
  class Yielder
5
- attr_accessor :ds, :of, :start, :finish
5
+ attr_accessor :ds, :of, :start, :finish, :order
6
6
  attr_writer :pk
7
7
 
8
- def initialize(ds:, pk: nil, of: 1000, start: nil, finish: nil)
8
+ def initialize(ds:, **options)
9
9
  self.ds = ds
10
- self.pk = pk
11
- self.of = of
12
- self.start = start
13
- self.finish = finish
10
+ self.pk = options.delete(:pk)
11
+ self.of = options.delete(:of) || 1000
12
+ self.start = options.delete(:start)
13
+ self.finish = options.delete(:finish)
14
+ self.order = options.delete(:order) || :asc
15
+
16
+ raise ArgumentError, ":order must be :asc or :desc, got #{order.inspect}" unless %i[asc desc].include?(order)
17
+ raise ArgumentError, "unknown options: #{options.keys.inspect}" if options.any?
14
18
  end
15
19
 
16
20
  def call
17
21
  base_ds = setup_base_ds or return
22
+ return enum_for(:call) unless block_given?
18
23
 
19
24
  current_instance = nil
20
25
 
21
26
  loop do
22
27
  working_ds =
23
28
  if current_instance
24
- base_ds.where(generate_conditions(current_instance.to_h, sign: :>))
29
+ base_ds.where(generate_conditions(current_instance.to_h, sign: sign_from_exclusive))
25
30
  else
26
31
  base_ds
27
32
  end
28
33
 
29
- working_ds_pk = working_ds.select(*qualified_pk).limit(of)
30
- current_instance = db.from(working_ds_pk).select(*pk).order(*pk).last or break
31
- working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: :<=))
34
+ working_ds_pk = working_ds.select(*qualified_pk).order(order_by).limit(of)
35
+ current_instance = db.from(working_ds_pk).select(*pk).order(order_by).last or break
36
+ working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: sign_to_inclusive))
32
37
 
33
38
  yield working_ds
34
39
  end
@@ -48,6 +53,27 @@ module Sequel::Extensions::Batches
48
53
  end
49
54
  end
50
55
 
56
+ def asc_order?
57
+ order == :asc
58
+ end
59
+
60
+ def sign_from_exclusive
61
+ asc_order? ? :> : :<
62
+ end
63
+
64
+ def sign_from_inclusive
65
+ asc_order? ? :>= : :<=
66
+ end
67
+
68
+ def sign_to_inclusive
69
+ asc_order? ? :<= : :>=
70
+ end
71
+
72
+ def order_by(qualified: false)
73
+ columns = qualified ? qualified_pk : pk
74
+ asc_order? ? Sequel.asc(columns) : Sequel.desc(columns)
75
+ end
76
+
51
77
  def qualified_pk
52
78
  @qualified_pk ||= pk.map { |x| Sequel[ds.first_source][x] }
53
79
  end
@@ -64,20 +90,18 @@ module Sequel::Extensions::Batches
64
90
  end
65
91
 
66
92
  def setup_base_ds
67
- base_ds = ds.order(*qualified_pk)
68
- base_ds = base_ds.where(generate_conditions(check_pk(start), sign: :>=)) if start
69
- base_ds = base_ds.where(generate_conditions(check_pk(finish), sign: :<=)) if finish
93
+ base_ds = ds.order(order_by(qualified: true))
94
+ base_ds = base_ds.where(generate_conditions(check_pk(start), sign: sign_from_inclusive)) if start
95
+ base_ds = base_ds.where(generate_conditions(check_pk(finish), sign: sign_to_inclusive)) if finish
70
96
 
71
- pk_ds = db.from(base_ds.select(*qualified_pk)).select(*pk).order(*pk)
97
+ pk_ds = db.from(base_ds.select(*qualified_pk)).select(*pk).order(order_by)
72
98
  actual_start = pk_ds.first
73
99
  actual_finish = pk_ds.last
74
100
 
75
101
  return unless actual_start && actual_finish
76
102
 
77
- base_ds = base_ds.where(generate_conditions(actual_start, sign: :>=))
78
- base_ds = base_ds.where(generate_conditions(actual_finish, sign: :<=))
79
-
80
- base_ds
103
+ base_ds = base_ds.where(generate_conditions(actual_start, sign: sign_from_inclusive))
104
+ base_ds.where(generate_conditions(actual_finish, sign: sign_to_inclusive))
81
105
  end
82
106
  end
83
107
  end
@@ -5,9 +5,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "sequel-batches"
8
- spec.version = "1.0.1"
8
+ spec.version = "1.1.0"
9
9
  spec.authors = %w[fiscal-cliff umbrellio]
10
10
  spec.email = ["oss@umbrellio.biz"]
11
+ spec.required_ruby_version = ">= 2.6"
11
12
 
12
13
  spec.summary = "The extension mimics AR5 batches api"
13
14
  spec.description = "Allows you to split your dataset in batches"
@@ -20,10 +21,14 @@ Gem::Specification.new do |spec|
20
21
  spec.add_runtime_dependency "sequel"
21
22
 
22
23
  spec.add_development_dependency "bundler"
23
- spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "bundler-audit"
25
+
24
26
  spec.add_development_dependency "pry"
25
27
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
28
+
27
29
  spec.add_development_dependency "rubocop-config-umbrellio"
30
+
31
+ spec.add_development_dependency "rspec"
28
32
  spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "simplecov-lcov"
29
34
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-batches
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fiscal-cliff
8
8
  - umbrellio
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-25 00:00:00.000000000 Z
12
+ date: 2022-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: coveralls
43
+ name: bundler-audit
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rspec
85
+ name: rubocop-config-umbrellio
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: rubocop-config-umbrellio
99
+ name: rspec
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov-lcov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
126
140
  description: Allows you to split your dataset in batches
127
141
  email:
128
142
  - oss@umbrellio.biz
@@ -130,10 +144,10 @@ executables: []
130
144
  extensions: []
131
145
  extra_rdoc_files: []
132
146
  files:
147
+ - ".github/workflows/ci.yml"
133
148
  - ".gitignore"
134
149
  - ".rspec"
135
150
  - ".rubocop.yml"
136
- - ".travis.yml"
137
151
  - CODE_OF_CONDUCT.md
138
152
  - Gemfile
139
153
  - LICENSE.txt
@@ -147,7 +161,7 @@ homepage: https://github.com/umbrellio/sequel-batches
147
161
  licenses:
148
162
  - MIT
149
163
  metadata: {}
150
- post_install_message:
164
+ post_install_message:
151
165
  rdoc_options: []
152
166
  require_paths:
153
167
  - lib
@@ -155,15 +169,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
169
  requirements:
156
170
  - - ">="
157
171
  - !ruby/object:Gem::Version
158
- version: '0'
172
+ version: '2.6'
159
173
  required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  requirements:
161
175
  - - ">="
162
176
  - !ruby/object:Gem::Version
163
177
  version: '0'
164
178
  requirements: []
165
- rubygems_version: 3.1.2
166
- signing_key:
179
+ rubygems_version: 3.3.19
180
+ signing_key:
167
181
  specification_version: 4
168
182
  summary: The extension mimics AR5 batches api
169
183
  test_files: []
data/.travis.yml DELETED
@@ -1,25 +0,0 @@
1
- sudo: false
2
-
3
- language: ruby
4
-
5
- rvm:
6
- - 2.3
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- - jruby-9.2.8.0
11
- - ruby-head
12
- - jruby-head
13
-
14
- before_install: gem install bundler
15
-
16
- addons:
17
- postgresql: "9.6"
18
-
19
- services:
20
- - postgresql
21
-
22
- matrix:
23
- allow_failures:
24
- - rvm: ruby-head
25
- - rvm: jruby-head