rails_compatibility 0.0.1 → 0.0.6

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: d7a818be9a687559746841473b529eca8dec7a850342ca9f943c9528318340e9
4
- data.tar.gz: 4cdcc971d081bf02117c193fb738d4fe2f8d3a2d979a1aeaccf24afa2bf7962d
3
+ metadata.gz: 1f0a8bf0a252bd80fd89c2c9e74271704669413cf8f84ff57c8d7499057adcc4
4
+ data.tar.gz: cebe77b327bb26d893fb1397ac2c1b3ebf93ad387ae3a3d1befea255ab3cdf93
5
5
  SHA512:
6
- metadata.gz: 7461f5853dd3c0edac4aa69a5bb3ab4776ea37e04663a2962f8fe555b1718cb8cdaf303ca6117ecad13da7c9fed61392583e93e0286570119a95d000f4798869
7
- data.tar.gz: abae820380d89420793d2147ab836768876022f7ba49f210ac497fb23682227f8257557de03f30c76d4f8251f7eb19c22acde255914773f65334f4f12565021e
6
+ metadata.gz: c7ef487f53d011bc4fac483b592d26c64c6e110107bca035488885004f7e800de0c46b6af4fcad0fd01527823b11f154513eb9a56f8852cbdc418b9527ceeedd
7
+ data.tar.gz: 646e2089e7c6351fdcd54800a55cea5be2cd051aafbcfbed17e55e8affc5e52353abf1c2b4ddf76a3f7668b296e59bda9cb843a55f35f167bcced2a062476f99
@@ -0,0 +1,62 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - 'README.md'
7
+ - 'CHANGELOG.md'
8
+ pull_request:
9
+ branches: [ master ]
10
+ paths-ignore:
11
+ - 'README.md'
12
+ - 'CHANGELOG.md'
13
+
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ name: Test
18
+ if: "contains(github.event.commits[0].message, '[ci skip]') == false"
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby:
23
+ - 2.2
24
+ - 2.6
25
+ - 2.7
26
+ gemfile:
27
+ - 3.2.gemfile
28
+ - 4.2.gemfile
29
+ - 5.0.gemfile
30
+ - 5.1.gemfile
31
+ - 5.2.gemfile
32
+ - 6.0.gemfile
33
+ - 6.1.gemfile
34
+ exclude:
35
+ - gemfile: 3.2.gemfile
36
+ ruby: 2.6
37
+ - gemfile: 3.2.gemfile
38
+ ruby: 2.7
39
+ - gemfile: 4.2.gemfile
40
+ ruby: 2.7
41
+ - gemfile: 6.0.gemfile
42
+ ruby: 2.2
43
+ - gemfile: 6.1.gemfile
44
+ ruby: 2.2
45
+ env:
46
+ BUNDLE_GEMFILE: "gemfiles/${{ matrix.gemfile }}"
47
+
48
+ steps:
49
+ - name: Checkout
50
+ uses: actions/checkout@v2
51
+ - name: Setup Ruby
52
+ uses: ruby/setup-ruby@v1
53
+ with:
54
+ ruby-version: ${{ matrix.ruby }}
55
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
56
+ - name: Run tests
57
+ run: bundle exec rake
58
+ - name: Publish code coverage
59
+ if: ${{ success() }}
60
+ uses: paambaati/codeclimate-action@v2.7.5
61
+ env:
62
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /gemfiles/*.gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc/
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rails
4
+
1
5
  AllCops:
2
6
  DisabledByDefault: true
3
7
  Exclude: []
@@ -73,10 +77,6 @@ Layout/EndAlignment:
73
77
  Description: 'Align ends correctly.'
74
78
  Enabled: true
75
79
 
76
- Lint/EndInMethod:
77
- Description: 'END blocks should not be placed inside method definitions.'
78
- Enabled: true
79
-
80
80
  Lint/EnsureReturn:
81
81
  Description: 'Do not use return in an ensure block.'
82
82
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure'
@@ -90,7 +90,7 @@ Lint/FormatParameterMismatch:
90
90
  Description: 'The number of parameters to format/sprint must match the fields.'
91
91
  Enabled: true
92
92
 
93
- Lint/HandleExceptions:
93
+ Lint/SuppressedException:
94
94
  Description: "Don't suppress exception."
95
95
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
96
96
  Enabled: true
@@ -139,7 +139,7 @@ Lint/ShadowingOuterLocalVariable:
139
139
  for block arguments or block local variables.
140
140
  Enabled: true
141
141
 
142
- Lint/StringConversionInInterpolation:
142
+ Lint/RedundantStringCoercion:
143
143
  Description: 'Checks for Object#to_s usage in string interpolation.'
144
144
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-to-s'
145
145
  Enabled: true
@@ -148,7 +148,7 @@ Lint/UnderscorePrefixedVariableName:
148
148
  Description: 'Do not use prefix `_` for a variable that is used.'
149
149
  Enabled: true
150
150
 
151
- Lint/UnneededCopDisableDirective:
151
+ Lint/RedundantCopDisableDirective:
152
152
  Description: >-
153
153
  Checks for rubocop:disable comments that can be removed.
154
154
  Note: this cop is not disabled when disabling all cops.
@@ -178,7 +178,7 @@ Lint/UselessAssignment:
178
178
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
179
179
  Enabled: true
180
180
 
181
- Lint/UselessComparison:
181
+ Lint/BinaryOperatorWithIdenticalOperands:
182
182
  Description: 'Checks for comparison of something with itself.'
183
183
  Enabled: true
184
184
 
@@ -221,7 +221,7 @@ Metrics/CyclomaticComplexity:
221
221
  of test cases needed to validate a method.
222
222
  Enabled: true
223
223
 
224
- Metrics/LineLength:
224
+ Layout/LineLength:
225
225
  Description: 'Limit lines to 120 characters.'
226
226
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
227
227
  Max: 120
@@ -285,7 +285,7 @@ Performance/ReverseEach:
285
285
  Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
286
286
  Enabled: true
287
287
 
288
- Performance/Sample:
288
+ Style/Sample:
289
289
  Description: >-
290
290
  Use `sample` instead of `shuffle.first`,
291
291
  `shuffle.last`, and `shuffle[Fixnum]`.
@@ -353,7 +353,7 @@ Rails/TimeZone:
353
353
  Description: 'Checks the correct usage of time zone aware methods.'
354
354
  StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
355
355
  Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
356
- Enabled: true
356
+ Enabled: false
357
357
 
358
358
  Rails/Validation:
359
359
  Description: 'Use validates :attribute, hash of validations.'
@@ -375,21 +375,21 @@ Style/Alias:
375
375
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method'
376
376
  Enabled: true
377
377
 
378
- Layout/AlignArray:
378
+ Layout/ArrayAlignment:
379
379
  Description: >-
380
380
  Align the elements of an array literal if they span more than
381
381
  one line.
382
382
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays'
383
383
  Enabled: true
384
384
 
385
- Layout/AlignHash:
385
+ Layout/HashAlignment:
386
386
  Description: >-
387
387
  Align the elements of a hash literal if they span more than
388
388
  one line.
389
389
  EnforcedHashRocketStyle: table
390
390
  Enabled: true
391
391
 
392
- Layout/AlignParameters:
392
+ Layout/ParameterAlignment:
393
393
  Description: >-
394
394
  Align the parameters of a method call if they span more
395
395
  than one line.
@@ -448,10 +448,6 @@ Style/BlockDelimiters:
448
448
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
449
449
  Enabled: true
450
450
 
451
- Style/BracesAroundHashParameters:
452
- Description: 'Enforce braces style around hash parameters.'
453
- Enabled: true
454
-
455
451
  Style/CaseEquality:
456
452
  Description: 'Avoid explicit use of the case equality operator(===).'
457
453
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality'
@@ -596,7 +592,7 @@ Style/EndBlock:
596
592
  Layout/EndOfLine:
597
593
  Description: 'Use Unix-style line endings.'
598
594
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf'
599
- Enabled: true
595
+ Enabled: false
600
596
 
601
597
  Style/EvenOdd:
602
598
  Description: 'Favor the use of Fixnum#even? && Fixnum#odd?'
@@ -617,14 +613,14 @@ Layout/InitialIndentation:
617
613
  Checks the indentation of the first non-blank non-comment line in a file.
618
614
  Enabled: true
619
615
 
620
- Layout/IndentFirstArgument:
616
+ Layout/FirstArgumentIndentation:
621
617
  Description: 'Checks the indentation of the first parameter in a method call.'
622
618
  Enabled: true
623
619
 
624
- Style/FlipFlop:
620
+ Lint/FlipFlop:
625
621
  Description: 'Checks for flip flops'
626
622
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops'
627
- Enabled: true
623
+ Enabled: false
628
624
 
629
625
  Style/For:
630
626
  Description: 'Checks use of for or each in multiline loops.'
@@ -634,9 +630,12 @@ Style/For:
634
630
  Style/FormatString:
635
631
  Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.'
636
632
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf'
637
- EnforcedStyle: sprintf
633
+ EnforcedStyle: percent
638
634
  Enabled: true
639
635
 
636
+ Style/FormatStringToken:
637
+ Enabled: false
638
+
640
639
  Style/GlobalVars:
641
640
  Description: 'Do not introduce global variables.'
642
641
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars'
@@ -676,14 +675,14 @@ Layout/IndentationWidth:
676
675
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
677
676
  Enabled: true
678
677
 
679
- Layout/IndentFirstArrayElement:
678
+ Layout/FirstArrayElementIndentation:
680
679
  Description: >-
681
680
  Checks the indentation of the first element in an array
682
681
  literal.
683
682
  EnforcedStyle: consistent
684
683
  Enabled: true
685
684
 
686
- Layout/IndentFirstHashElement:
685
+ Layout/FirstHashElementIndentation:
687
686
  Description: 'Checks the indentation of the first key in a hash literal.'
688
687
  EnforcedStyle: consistent
689
688
  Enabled: true
@@ -862,7 +861,7 @@ Style/PercentQLiterals:
862
861
  Style/PerlBackrefs:
863
862
  Description: 'Avoid Perl-style regex back references.'
864
863
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
865
- Enabled: true
864
+ Enabled: false
866
865
 
867
866
  Naming/PredicateName:
868
867
  Description: 'Check the names of predicate methods.'
@@ -940,11 +939,11 @@ Style/SingleLineBlockParams:
940
939
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks'
941
940
  Methods:
942
941
  - reduce:
943
- - acc
944
- - elem
942
+ - sum
943
+ - v
945
944
  - inject:
946
- - acc
947
- - elem
945
+ - sum
946
+ - v
948
947
  Enabled: true
949
948
 
950
949
  Style/SingleLineMethods:
@@ -1118,12 +1117,12 @@ Style/SymbolProc:
1118
1117
  Description: 'Use symbols as procs instead of blocks when possible.'
1119
1118
  Enabled: true
1120
1119
 
1121
- Layout/Tab:
1120
+ Layout/IndentationStyle:
1122
1121
  Description: 'No hard tabs.'
1123
1122
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
1124
1123
  Enabled: true
1125
1124
 
1126
- Layout/TrailingBlankLines:
1125
+ Layout/TrailingEmptyLines:
1127
1126
  Description: 'Checks trailing blank lines and final newline.'
1128
1127
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof'
1129
1128
  Enabled: true
@@ -1178,11 +1177,11 @@ Style/UnlessElse:
1178
1177
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless'
1179
1178
  Enabled: true
1180
1179
 
1181
- Style/UnneededCapitalW:
1180
+ Style/RedundantCapitalW:
1182
1181
  Description: 'Checks for %W when interpolation is not needed.'
1183
1182
  Enabled: true
1184
1183
 
1185
- Style/UnneededPercentQ:
1184
+ Style/RedundantPercentQ:
1186
1185
  Description: 'Checks for %q/%Q when single quotes or double quotes would do.'
1187
1186
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q'
1188
1187
  Enabled: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## Change Log
2
+
3
+ ### [v0.0.5](https://github.com/khiav223577/rails_compatibility/compare/v0.0.4...v0.0.5) 2021/05/05
4
+ - [#10](https://github.com/khiav223577/rails_compatibility/pull/10) Implement #pick (@khiav223577)
5
+ - [#9](https://github.com/khiav223577/rails_compatibility/pull/9) refactor: use GTE_RAILS_4_0 (@khiav223577)
6
+
7
+ ### [v0.0.4](https://github.com/khiav223577/rails_compatibility/compare/v0.0.3...v0.0.4) 2021/04/10
8
+ - [#8](https://github.com/khiav223577/rails_compatibility/pull/8) Fix: join dependency construct wrongly when HABTM associations have custom name (@khiav223577)
9
+
10
+ ### [v0.0.3](https://github.com/khiav223577/rails_compatibility/compare/v0.0.2...v0.0.3) 2021/02/09
11
+ - [#7](https://github.com/khiav223577/rails_compatibility/pull/7) Implement #build_joins (@khiav223577)
12
+ - [#6](https://github.com/khiav223577/rails_compatibility/pull/6) Support Rails 6.1 (@khiav223577)
13
+ - [#5](https://github.com/khiav223577/rails_compatibility/pull/5) Migrating from Travis CI to GitHub Actions (@khiav223577)
14
+ - [#4](https://github.com/khiav223577/rails_compatibility/pull/4) Fix: test files should not be included in coverage (@khiav223577)
15
+ - [#3](https://github.com/khiav223577/rails_compatibility/pull/3) Support Ruby 2.7 (@khiav223577)
16
+
17
+ ### [v0.0.2](https://github.com/khiav223577/rails_compatibility/compare/v0.0.1...v0.0.2) 2019/12/18
18
+ - [#2](https://github.com/khiav223577/rails_compatibility/pull/2) Implement `attribute_types` (@khiav223577)
19
+
20
+ ### v0.0.1 2019/12/17
21
+ - [#1](https://github.com/khiav223577/rails_compatibility/pull/1) Implement `unscope_where` (@khiav223577)
data/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  # RailsCompatibility
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/rails_compatibility.svg?style=flat)](http://rubygems.org/gems/rails_compatibility)
4
- [![Build Status](https://travis-ci.org/khiav223577/rails_compatibility.svg?branch=master)](https://travis-ci.org/khiav223577/rails_compatibility)
4
+ [![Build Status](https://github.com/khiav223577/rails_compatibility/workflows/Ruby/badge.svg)](https://github.com/khiav223577/rails_compatibility/actions)
5
5
  [![RubyGems](http://img.shields.io/gem/dt/rails_compatibility.svg?style=flat)](http://rubygems.org/gems/rails_compatibility)
6
6
  [![Code Climate](https://codeclimate.com/github/khiav223577/rails_compatibility/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/rails_compatibility)
7
7
  [![Test Coverage](https://codeclimate.com/github/khiav223577/rails_compatibility/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/rails_compatibility/coverage)
8
8
 
9
+ ## Supports
10
+ - Ruby 2.2 ~ 2.7
11
+ - Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0
12
+
9
13
  ## Installation
10
14
 
11
15
  Provides cross-rails methods for you to upgrade rails, backport features, create easy-to-maintain gems, and so on.
12
- Support Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0.
13
- Support Ruby 2.2 ~ 2.6
14
16
 
15
17
  ```ruby
16
18
  gem 'rails_compatibility'
data/gemfiles/3.2.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 3.2.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.3.6'
8
8
  end
9
9
 
data/gemfiles/4.2.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 4.2.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.3.6'
8
8
  end
9
9
 
data/gemfiles/5.0.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 5.0.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.3.6'
8
8
  end
9
9
 
data/gemfiles/5.1.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 5.1.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.3.6'
8
8
  end
9
9
 
data/gemfiles/5.2.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 5.2.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.3.6'
8
8
  end
9
9
 
data/gemfiles/6.0.gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'activerecord', '~> 6.0.0'
4
4
 
5
5
  group :test do
6
- gem 'simplecov'
6
+ gem 'simplecov', '< 0.18'
7
7
  gem 'sqlite3', '~> 1.4.1'
8
8
  end
9
9
 
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.1.1'
4
+ gem 'pluck_all', '~> 2.2.1'
5
+
6
+ group :test do
7
+ gem 'simplecov', '< 0.18'
8
+ gem 'sqlite3', '~> 1.4.1'
9
+ end
10
+
11
+ gemspec path: '../'
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility'
4
+ require 'active_record'
5
+
6
+ class << RailsCompatibility
7
+ GTE_RAILS_6_1 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.1.0')
8
+ GTE_RAILS_6_0 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.0.0')
9
+ GTE_RAILS_5_2 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.2.0')
10
+ GTE_RAILS_5_1 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1.0')
11
+ GTE_RAILS_5_0 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.0.0')
12
+ GTE_RAILS_4_0 = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('4.0.0')
13
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility'
4
+ require 'rails_compatibility/active_record'
5
+
6
+ class << RailsCompatibility
7
+ if ActiveRecord::Base.respond_to?(:attribute_types) # column_types was changed to attribute_types in Rails 5
8
+ def attribute_types(klass)
9
+ klass.attribute_types
10
+ end
11
+ elsif ActiveRecord::Base.respond_to?(:column_types) # Rails 4
12
+ def attribute_types(klass)
13
+ klass.column_types
14
+ end
15
+ else # In Rails 3
16
+ def attribute_types(klass)
17
+ klass.columns_hash
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility'
4
+ require 'rails_compatibility/construct_join_dependency'
5
+ require 'rails_compatibility/active_record'
6
+
7
+ class << RailsCompatibility
8
+ if GTE_RAILS_6_1
9
+ def build_joins(reflect, relation)
10
+ join_dependency = construct_join_dependency(reflect, relation)
11
+ joins = join_dependency.join_constraints([], relation.alias_tracker, relation.references_values)
12
+ return joins
13
+ end
14
+ elsif GTE_RAILS_6_0
15
+ def build_joins(reflect, relation)
16
+ join_dependency = construct_join_dependency(reflect, relation)
17
+ joins = join_dependency.join_constraints([], relation.alias_tracker)
18
+ return joins
19
+ end
20
+ elsif GTE_RAILS_5_2
21
+ def build_joins(reflect, relation)
22
+ join_dependency = construct_join_dependency(reflect, relation)
23
+ joins = join_dependency.join_constraints([], Arel::Nodes::InnerJoin, relation.alias_tracker)
24
+ return joins
25
+ end
26
+ elsif GTE_RAILS_5_0
27
+ def build_joins(reflect, relation)
28
+ join_dependency = construct_join_dependency(reflect, relation)
29
+ info = join_dependency.join_constraints([], Arel::Nodes::InnerJoin)[0]
30
+ return info.joins
31
+ end
32
+ elsif GTE_RAILS_4_0
33
+ def build_joins(reflect, relation)
34
+ join_dependency = construct_join_dependency(reflect, relation)
35
+ info = join_dependency.join_constraints([])[0]
36
+ return info.joins
37
+ end
38
+ else
39
+ def build_joins(reflect, relation)
40
+ join_dependency = construct_join_dependency(reflect, relation)
41
+ return join_dependency.join_associations
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility'
4
+ require 'rails_compatibility/active_record'
5
+
6
+ class << RailsCompatibility
7
+ if GTE_RAILS_6_0
8
+ def construct_join_dependency(reflect, relation)
9
+ joins = inverse_association_joins(reflect)
10
+ return relation.construct_join_dependency(joins, Arel::Nodes::InnerJoin)
11
+ end
12
+ elsif GTE_RAILS_5_2
13
+ def construct_join_dependency(reflect, relation)
14
+ joins = inverse_association_joins(reflect)
15
+
16
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(reflect.klass, relation.table, joins)
17
+
18
+ root = join_dependency.send(:join_root)
19
+
20
+ join_dependency.instance_variable_set(:@alias_tracker, relation.alias_tracker)
21
+ join_dependency.send(:construct_tables!, root)
22
+ return join_dependency
23
+ end
24
+ else
25
+ def construct_join_dependency(reflect, _relation)
26
+ joins = inverse_association_joins(reflect)
27
+ return ActiveRecord::Associations::JoinDependency.new(reflect.klass, joins, [])
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def inverse_association_joins(reflect)
34
+ [reflect.options[:inverse_of] || reflect.active_record.table_name]
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility'
4
+ require 'rails_compatibility/active_record'
5
+
6
+ class << RailsCompatibility
7
+ if GTE_RAILS_6_1
8
+ def has_include?(relation, column_name)
9
+ relation.send(:has_include?, column_name)
10
+ end
11
+ elsif GTE_RAILS_5_0
12
+ def has_include?(relation, column_name)
13
+ relation.dup.send(:has_include?, column_name)
14
+ end
15
+ else
16
+ def has_include?(relation, column_name)
17
+ relation.send(:has_include?, column_name)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility/active_record'
4
+
5
+ class << RailsCompatibility
6
+ if GTE_RAILS_6_0
7
+ def pick(relation, *args)
8
+ relation.pick(*args)
9
+ end
10
+ elsif GTE_RAILS_4_0
11
+ def pick(relation, *args)
12
+ relation.limit(1).pluck(*args).first
13
+ end
14
+ else
15
+ def pick(relation, *args)
16
+ model = relation.first
17
+
18
+ return nil if model == nil
19
+ return model[args.first] if args.size == 1
20
+ return args.map{|s| model[s] }
21
+ end
22
+ end
23
+ end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
3
+ require 'rails_compatibility/active_record'
4
4
 
5
5
  class << RailsCompatibility
6
- if ActiveRecord::VERSION::MAJOR < 4
6
+ if GTE_RAILS_4_0
7
7
  def unscope_where(relation)
8
- relation.dup.tap{|s| s.where_values = [] }
8
+ relation.unscope(:where)
9
9
  end
10
10
  else
11
11
  def unscope_where(relation)
12
- relation.unscope(:where)
12
+ relation.dup.tap{|s| s.where_values = [] }
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module RailsCompatibility
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,43 +1,44 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rails_compatibility/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'rails_compatibility'
8
- spec.version = RailsCompatibility::VERSION
9
- spec.authors = ['khiav reoy']
10
- spec.email = ['mrtmrt15xn@yahoo.com.tw']
11
-
12
- spec.summary = 'Provides cross-rails methods for you to upgrade rails, backport features, create easy-to-maintain gems, and so on.'
13
- spec.description = 'Provides cross-rails methods for you to upgrade rails, backport features, create easy-to-maintain gems, and so on.'
14
- spec.homepage = 'https://github.com/khiav223577/rails_compatibility'
15
- spec.license = 'MIT'
16
-
17
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
- # delete this section to allow pushing this gem to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
- # end
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = 'exe'
27
- spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
28
- spec.require_paths = ['lib']
29
- spec.metadata = {
30
- 'homepage_uri' => 'https://github.com/khiav223577/rails_compatibility',
31
- 'changelog_uri' => 'https://github.com/khiav223577/rails_compatibility/blob/master/CHANGELOG.md',
32
- 'source_code_uri' => 'https://github.com/khiav223577/rails_compatibility',
33
- 'documentation_uri' => 'https://www.rubydoc.info/gems/rails_compatibility',
34
- 'bug_tracker_uri' => 'https://github.com/khiav223577/rails_compatibility/issues',
35
- }
36
-
37
- spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
38
- spec.add_development_dependency 'rake', '~> 12.0'
39
- spec.add_development_dependency 'sqlite3', '~> 1.3'
40
- spec.add_development_dependency 'minitest', '~> 5.0'
41
-
42
- spec.add_dependency 'activerecord', '>= 3'
43
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_compatibility/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails_compatibility'
8
+ spec.version = RailsCompatibility::VERSION
9
+ spec.authors = ['khiav reoy']
10
+ spec.email = ['mrtmrt15xn@yahoo.com.tw']
11
+
12
+ spec.summary = 'Provides cross-rails methods for you to upgrade rails, backport features, create easy-to-maintain gems, and so on.'
13
+ spec.description = 'Provides cross-rails methods for you to upgrade rails, backport features, create easy-to-maintain gems, and so on.'
14
+ spec.homepage = 'https://github.com/khiav223577/rails_compatibility'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ spec.metadata = {
30
+ 'homepage_uri' => 'https://github.com/khiav223577/rails_compatibility',
31
+ 'changelog_uri' => 'https://github.com/khiav223577/rails_compatibility/blob/master/CHANGELOG.md',
32
+ 'source_code_uri' => 'https://github.com/khiav223577/rails_compatibility',
33
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/rails_compatibility',
34
+ 'bug_tracker_uri' => 'https://github.com/khiav223577/rails_compatibility/issues',
35
+ }
36
+
37
+ spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
38
+ spec.add_development_dependency 'rake', '~> 12.0'
39
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
40
+ spec.add_development_dependency 'minitest', '~> 5.0'
41
+ spec.add_development_dependency 'backports', '~> 3.15.0'
42
+
43
+ spec.add_dependency 'activerecord', '>= 3'
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_compatibility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '5.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: backports
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 3.15.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.15.0
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: activerecord
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -94,9 +108,10 @@ executables: []
94
108
  extensions: []
95
109
  extra_rdoc_files: []
96
110
  files:
111
+ - ".github/workflows/ruby.yml"
97
112
  - ".gitignore"
98
113
  - ".rubocop.yml"
99
- - ".travis.yml"
114
+ - CHANGELOG.md
100
115
  - CODE_OF_CONDUCT.md
101
116
  - LICENSE
102
117
  - LICENSE.txt
@@ -110,7 +125,14 @@ files:
110
125
  - gemfiles/5.1.gemfile
111
126
  - gemfiles/5.2.gemfile
112
127
  - gemfiles/6.0.gemfile
128
+ - gemfiles/6.1.gemfile
113
129
  - lib/rails_compatibility.rb
130
+ - lib/rails_compatibility/active_record.rb
131
+ - lib/rails_compatibility/attribute_types.rb
132
+ - lib/rails_compatibility/build_joins.rb
133
+ - lib/rails_compatibility/construct_join_dependency.rb
134
+ - lib/rails_compatibility/has_include.rb
135
+ - lib/rails_compatibility/pick.rb
114
136
  - lib/rails_compatibility/unscope_where.rb
115
137
  - lib/rails_compatibility/version.rb
116
138
  - rails_compatibility.gemspec
@@ -138,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
160
  - !ruby/object:Gem::Version
139
161
  version: '0'
140
162
  requirements: []
141
- rubygems_version: 3.0.3
163
+ rubygems_version: 3.2.14
142
164
  signing_key:
143
165
  specification_version: 4
144
166
  summary: Provides cross-rails methods for you to upgrade rails, backport features,
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- sudo: false
2
- env:
3
- global:
4
- - CC_TEST_REPORTER_ID=bc86bdb762b05f34d8c71dd53717ea5b3a83bda4b5a4ba684037d20076a186ec
5
- language: ruby
6
- rvm:
7
- - 2.2
8
- - 2.6
9
- gemfile:
10
- - gemfiles/3.2.gemfile
11
- - gemfiles/4.2.gemfile
12
- - gemfiles/5.0.gemfile
13
- - gemfiles/5.1.gemfile
14
- - gemfiles/5.2.gemfile
15
- - gemfiles/6.0.gemfile
16
- matrix:
17
- exclude:
18
- - gemfile: gemfiles/3.2.gemfile
19
- rvm: 2.6
20
- - gemfile: gemfiles/4.0.gemfile
21
- rvm: 2.6
22
- - gemfile: gemfiles/6.0.gemfile
23
- rvm: 2.2
24
- before_install:
25
- - gem i rubygems-update -v '<3' && update_rubygems
26
- - gem install bundler -v 1.17.3
27
- - gem --version
28
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
29
- - chmod +x ./cc-test-reporter
30
- - ./cc-test-reporter before-build
31
- script:
32
- - bundle exec rake test
33
- after_script:
34
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT