activerecord-cte 0.1.3 → 0.1.4

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: e2fbfad4eca9d8be81cde9c22367e6cf29020baad9411acfffe4abe2f51d99fe
4
- data.tar.gz: 39cacb9b310c315c5e0fff63a88903e69b4a618b324f0bcabfe78f4b70530a01
3
+ metadata.gz: 9c5fd306f910ad7183f278dfbbf91363e7825a823f31fbb798693a8a529db23c
4
+ data.tar.gz: aa0dcc304d3469394b2e0eb6496ddfac22632df5febc0d43f71302fbbdbfe3d6
5
5
  SHA512:
6
- metadata.gz: b1a1428a7916fd20c25d758a68cbcc9d39c3e737e462b01467226cc4a7fec68ad86fce2aadd7c2452170979cd8e7bff6fc0026e51a15a886e4bee8ea42eb6332
7
- data.tar.gz: 488b14ed1cff2d0271188eeb0457432a38eb51637c44d4e2015ca1624ee646c42b426a7cb8f583b94f8baadc2e90abf2fd59d5aa3bc8d70b3c5a22746c631457
6
+ metadata.gz: c13b4cb8fe44d0380856fbac382f27f9881d03dcb6d9c6fb21d0cb1c5d2704d09d0e51432b165816f939d1ce46957d877ffc84bdeda837d20604d78065ccfa4b
7
+ data.tar.gz: a64ff3e533e71d04437f706197266782fd5ab3ec8fe4df047814cd2ffda5dc9bea24040bb93ddfb4b794c068e57df4d5f710d8b941a7cbe8384c57cc039c2db8
@@ -0,0 +1,12 @@
1
+ name: Rubocop
2
+ on: [push]
3
+ jobs:
4
+ Rubocop:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - name: Check out repository code
8
+ uses: actions/checkout@v2
9
+ - name: Setup Ruby
10
+ uses: ruby/setup-ruby@v1
11
+ - run: bundle install
12
+ - run: bundle exec rubocop
@@ -0,0 +1,25 @@
1
+ name: MySql
2
+ on: [push]
3
+ jobs:
4
+ Test-With-Mysql:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ active_record: [6.0.4, 5.2.6]
10
+ env:
11
+ ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
12
+ DATABASE_ADAPTER: mysql
13
+ INSTALL_MYSQL_GEM: true
14
+ RAILS_ENV: test
15
+ steps:
16
+ - name: Check out repository code
17
+ uses: actions/checkout@v2
18
+ - name: Start mysql
19
+ run: sudo service mysql start
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
24
+ - name: Run tests
25
+ run: bundle exec rake test
@@ -0,0 +1,34 @@
1
+ name: PostgreSQL
2
+ on: [push]
3
+ jobs:
4
+ Test-With-PostgreSQL:
5
+ runs-on: ubuntu-latest
6
+ container: ruby:2.7
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ active_record: [6.0.4, 5.2.6]
11
+ env:
12
+ ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
13
+ DATABASE_ADAPTER: postgresql
14
+ INSTALL_PG_GEM: true
15
+ RAILS_ENV: test
16
+ services:
17
+ postgres:
18
+ image: postgres
19
+ env:
20
+ POSTGRES_PASSWORD: postgres
21
+ options: >-
22
+ --health-cmd pg_isready
23
+ --health-interval 10s
24
+ --health-timeout 5s
25
+ --health-retries 5
26
+ ports:
27
+ - 5432:5432
28
+ steps:
29
+ - name: Check out repository code
30
+ uses: actions/checkout@v2
31
+ - name: Bundle dependencies
32
+ run: bundle install
33
+ - name: Run tests
34
+ run: bundle exec rake test
@@ -0,0 +1,22 @@
1
+ name: SQLite
2
+ on: [push]
3
+ jobs:
4
+ Test-With-SQLite:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ active_record: [6.0.4, 5.2.6]
10
+ env:
11
+ ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
12
+ DATABASE_ADAPTER: sqlite3
13
+ RAILS_ENV: test
14
+ steps:
15
+ - name: Check out repository code
16
+ uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
21
+ - name: Run tests
22
+ run: bundle exec rake test
data/.rubocop.yml CHANGED
@@ -1,8 +1,14 @@
1
1
  require:
2
+ - rubocop-minitest
2
3
  - rubocop-performance
4
+ - rubocop-rake
3
5
 
4
6
  AllCops:
5
- TargetRubyVersion: 2.6
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.7
9
+
10
+ Gemspec/RequiredRubyVersion:
11
+ Enabled: false
6
12
 
7
13
  Layout/LineLength:
8
14
  AllowHeredoc: true
@@ -10,15 +16,30 @@ Layout/LineLength:
10
16
  IgnoreCopDirectives: true
11
17
  Max: 120
12
18
  Exclude:
19
+ - "activerecord-cte.gemspec"
13
20
  - "test/**/*"
14
21
 
22
+ Layout/MultilineMethodCallIndentation:
23
+ EnforcedStyle: indented
24
+
15
25
  Metrics/AbcSize:
16
26
  Exclude:
17
- - "test/**/*"
27
+ - "test/**/*_test.rb"
28
+
29
+ Metrics/ClassLength:
30
+ Exclude:
31
+ - "test/**/*_test.rb"
18
32
 
19
33
  Metrics/CyclomaticComplexity:
20
34
  Max: 7
21
35
 
36
+ Metrics/MethodLength:
37
+ Exclude:
38
+ - "test/**/*_test.rb"
39
+
40
+ Minitest/MultipleAssertions:
41
+ Max: 5
42
+
22
43
  Style/ClassAndModuleChildren:
23
44
  Enabled: false
24
45
 
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.6
1
+ FROM ruby:2.7
2
2
 
3
3
  ENV APP_HOME /activerecord_cte
4
4
  RUN mkdir $APP_HOME
@@ -7,6 +7,7 @@ WORKDIR $APP_HOME
7
7
  ENV RAILS_ENV test
8
8
  ENV INSTALL_MYSQL_GEM true
9
9
  ENV INSTALL_PG_GEM true
10
+ ENV MYSQL_HOST mysql
10
11
 
11
12
  # Cache the bundle install
12
13
  COPY Gemfile* $APP_HOME/
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in activerecord-cte.gemspec
6
6
  gemspec
7
7
 
8
- ACTIVE_RECORD_VERSION = ENV.fetch("ACTIVE_RECORD_VERSION") { "6.0.2.1" }
8
+ ACTIVE_RECORD_VERSION = ENV.fetch("ACTIVE_RECORD_VERSION", "6.0.4")
9
9
 
10
10
  gem "activerecord", ACTIVE_RECORD_VERSION
11
11
 
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # ActiveRecord::Cte
2
2
 
3
+ ![Rubocop](https://github.com/vlado/activerecord-cte/actions/workflows/rubocop.yml/badge.svg)
4
+ ![MySQL](https://github.com/vlado/activerecord-cte/actions/workflows/test-with-mysql.yml/badge.svg)
5
+ ![PostgreSQL](https://github.com/vlado/activerecord-cte/actions/workflows/test-with-postgresql.yml/badge.svg)
6
+ ![SQLite](https://github.com/vlado/activerecord-cte/actions/workflows/test-with-sqlite.yml/badge.svg)
7
+
3
8
  Adds Common Table Expression support to ActiveRecord (Rails).
4
9
 
5
10
  It adds `.with` query method and makes it super easy to build and chain complex CTE queries. Let's explain it using simple example.
@@ -196,11 +201,27 @@ I decided to wait a bit :)
196
201
 
197
202
  After checking out the repo, run `bin/setup` to install dependencies.
198
203
 
204
+ ### Running Rubocop
205
+
206
+ ```
207
+ bundle exec rubocop
208
+ ```
209
+
199
210
  ### Running tests
200
211
 
201
- Run `rake test` to run the tests using SQLite adapter and latest version on Rails.
212
+ To run the tests using SQLite adapter and latest version on Rails run
213
+
214
+ ```
215
+ bundle exec rake test
216
+ ```
217
+
218
+ GitHub Actions will run the test matrix with multiple ActiveRecord versions and database adapters. You can also run the matrix locally with
219
+
220
+ ```
221
+ bundle exec rake test:matrix
222
+ ```
202
223
 
203
- To run tests using all supportted database adapters and ActiveRecord versions run `rake test:matrix`. This will build Docker image with all dependencies and run alll tests in it. See `bin/test` for more info.
224
+ This will build Docker image with all dependencies and run all tests in it. See `bin/test` for more info.
204
225
 
205
226
  ### Console
206
227
 
@@ -212,7 +233,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
212
233
 
213
234
  ## Contributing
214
235
 
215
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activerecord-cte. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
236
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vlado/activerecord-cte. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
216
237
 
217
238
  ## License
218
239
 
@@ -220,4 +241,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
220
241
 
221
242
  ## Code of Conduct
222
243
 
223
- Everyone interacting in the Activerecord::Cte project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activerecord-cte/blob/master/CODE_OF_CONDUCT.md).
244
+ Everyone interacting in the Activerecord::Cte project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vlado/activerecord-cte/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -12,7 +12,10 @@ end
12
12
  task default: :test
13
13
 
14
14
  namespace :test do
15
+ desc "Will run the tests in all db adapters - AR version combinations"
15
16
  task :matrix do
17
+ require "English"
16
18
  system("docker-compose build && docker-compose run lib bin/test")
19
+ exit($CHILD_STATUS.exitstatus) unless $CHILD_STATUS.success?
17
20
  end
18
21
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["vladocingel@gmail.com"]
12
12
 
13
13
  spec.summary = "Brings Common Table Expressions support to ActiveRecord and makes it super easy to build and chain complex CTE queries"
14
+ spec.description = spec.summary
14
15
  spec.homepage = "https://github.com/vlado/activerecord-cte"
15
16
  spec.license = "MIT"
16
17
 
@@ -19,6 +20,7 @@ Gem::Specification.new do |spec|
19
20
  spec.metadata["homepage_uri"] = spec.homepage
20
21
  spec.metadata["source_code_uri"] = "https://github.com/vlado/activerecord-cte"
21
22
 
23
+ spec.required_ruby_version = ">= 1.9.2"
22
24
  # Specify which files should be added to the gem when it is released.
23
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
@@ -33,7 +35,9 @@ Gem::Specification.new do |spec|
33
35
  spec.add_development_dependency "bundler", "~> 2.0"
34
36
  spec.add_development_dependency "minitest", "~> 5.0"
35
37
  spec.add_development_dependency "rake", "~> 13.0.1"
36
- spec.add_development_dependency "rubocop", "~> 0.80.1"
37
- spec.add_development_dependency "rubocop-performance", "~> 1.5.2"
38
+ spec.add_development_dependency "rubocop", "~> 1.17.0"
39
+ spec.add_development_dependency "rubocop-minitest", "~> 0.13.0"
40
+ spec.add_development_dependency "rubocop-performance", "~> 1.11.3"
41
+ spec.add_development_dependency "rubocop-rake", "~> 0.5.1"
38
42
  spec.add_development_dependency "sqlite3"
39
43
  end
data/bin/test CHANGED
@@ -1,26 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "English"
5
+
4
6
  ADAPTERS = %w[
5
7
  mysql
6
8
  postgresql
7
9
  sqlite3
8
- ]
9
- AR_VERSIONS = %w[
10
- 6.0.2.1
11
- 5.2.4.1
12
- ]
13
-
14
- ORIGINAL_AR_VERSION = `bundle show activerecord`.split("-").last.strip
15
-
16
- AR_VERSIONS.each do |ar_version|
17
- puts "----> Running tests with ActiveRecord #{ar_version}"
18
- system("ACTIVE_RECORD_VERSION=#{ar_version} bundle update activerecord") unless ar_version == ORIGINAL_AR_VERSION
19
- ADAPTERS.each do |adapter|
20
- puts "----> Running tests with #{adapter} adapter"
21
- system("DATABASE_ADAPTER=#{adapter} ACTIVE_RECORD_VERSION=#{ar_version} bundle exec rake")
10
+ ].freeze
11
+
12
+ ACTIVE_RECORD_VERSIONS = %w[
13
+ 6.0.4
14
+ 5.2.6
15
+ ].freeze
16
+
17
+ class Matrix
18
+ def self.run
19
+ new.run
20
+ end
21
+
22
+ def initialize
23
+ @exit_status_code = 0
24
+ end
25
+
26
+ def run # rubocop:disable Metrics/MethodLength
27
+ original_ar_version = `bundle show activerecord`.split("-").last.strip
28
+ ACTIVE_RECORD_VERSIONS.each do |ar_version|
29
+ puts "----> Switching ActiveRecord to version #{ar_version}"
30
+ cmd("ACTIVE_RECORD_VERSION=#{ar_version} bundle update activerecord")
31
+
32
+ ADAPTERS.each do |adapter|
33
+ puts "----> Running tests with ActiveRecord #{ar_version} and #{adapter} adapter"
34
+ cmd("DATABASE_ADAPTER=#{adapter} ACTIVE_RECORD_VERSION=#{ar_version} bundle exec rake test")
35
+ end
36
+ end
37
+
38
+ puts "----> Reverting back to original ActiveRecord version (#{original_ar_version})"
39
+ cmd("ACTIVE_RECORD_VERSION=#{original_ar_version} bundle update activerecord")
40
+
41
+ exit(@exit_status_code) unless @exit_status_code.zero?
42
+ end
43
+
44
+ private
45
+
46
+ def cmd(cmd)
47
+ system(cmd)
48
+ @exit_status_code = $CHILD_STATUS.exitstatus unless $CHILD_STATUS.success?
22
49
  end
23
50
  end
24
51
 
25
- puts "----> Reverting back to original ActiveRecord version (#{ORIGINAL_AR_VERSION})"
26
- system("ACTIVE_RECORD_VERSION=#{ORIGINAL_AR_VERSION} bundle update activerecord")
52
+ Matrix.run
data/docker-compose.yml CHANGED
@@ -15,9 +15,9 @@ services:
15
15
  restart: always
16
16
  environment:
17
17
  MYSQL_DATABASE: activerecord_cte_test
18
- MYSQL_USER: user
19
- MYSQL_PASSWORD: secret
20
- MYSQL_ROOT_PASSWORD: secret
18
+ MYSQL_USER: root
19
+ MYSQL_PASSWORD: root
20
+ MYSQL_ROOT_PASSWORD: root
21
21
  ports:
22
22
  - 3306:3306
23
23
  expose:
@@ -28,8 +28,8 @@ services:
28
28
  restart: always
29
29
  environment:
30
30
  POSTGRES_DB: activerecord_cte_test
31
- POSTGRES_USER: user
32
- POSTGRES_PASSWORD: secret
31
+ POSTGRES_USER: postgres
32
+ POSTGRES_PASSWORD: postgres
33
33
  ports:
34
34
  - 5432:5432
35
35
  expose:
@@ -4,12 +4,8 @@ module ActiveRecord
4
4
  module Querying
5
5
  delegate :with, to: :all
6
6
  end
7
-
8
- module WithMerger
9
- def normal_values
10
- super + %i[with]
11
- end
12
7
 
8
+ module WithMerger
13
9
  def merge
14
10
  super
15
11
  merge_withs
@@ -56,7 +52,7 @@ module ActiveRecord
56
52
  arel
57
53
  end
58
54
 
59
- def build_with(arel) # rubocop:disable Metrics/MethodLength
55
+ def build_with(arel) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
60
56
  return if with_values.empty?
61
57
 
62
58
  recursive = with_values.delete(:recursive)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Activerecord
4
4
  module Cte
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlado Cingel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-30 00:00:00.000000000 Z
11
+ date: 2021-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -72,28 +72,56 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.80.1
75
+ version: 1.17.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.80.1
82
+ version: 1.17.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.13.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.13.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-performance
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 1.5.2
103
+ version: 1.11.3
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 1.5.2
110
+ version: 1.11.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.1
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: sqlite3
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -108,15 +136,21 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
- description:
139
+ description: Brings Common Table Expressions support to ActiveRecord and makes it
140
+ super easy to build and chain complex CTE queries
112
141
  email:
113
142
  - vladocingel@gmail.com
114
143
  executables: []
115
144
  extensions: []
116
145
  extra_rdoc_files: []
117
146
  files:
147
+ - ".github/workflows/rubocop.yml"
148
+ - ".github/workflows/test-with-mysql.yml"
149
+ - ".github/workflows/test-with-postgresql.yml"
150
+ - ".github/workflows/test-with-sqlite.yml"
118
151
  - ".gitignore"
119
152
  - ".rubocop.yml"
153
+ - ".ruby-version"
120
154
  - ".travis.yml"
121
155
  - ".vimrc"
122
156
  - CODE_OF_CONDUCT.md
@@ -148,14 +182,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
182
  requirements:
149
183
  - - ">="
150
184
  - !ruby/object:Gem::Version
151
- version: '0'
185
+ version: 1.9.2
152
186
  required_rubygems_version: !ruby/object:Gem::Requirement
153
187
  requirements:
154
188
  - - ">="
155
189
  - !ruby/object:Gem::Version
156
190
  version: '0'
157
191
  requirements: []
158
- rubygems_version: 3.0.3
192
+ rubygems_version: 3.1.6
159
193
  signing_key:
160
194
  specification_version: 4
161
195
  summary: Brings Common Table Expressions support to ActiveRecord and makes it super