rails_compatibility 0.0.5 → 0.0.6

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.
data/gemfiles/6.1.gemfile CHANGED
@@ -1,11 +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: '../'
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: '../'
@@ -1 +1 @@
1
- require 'rails_compatibility/version'
1
+ require 'rails_compatibility/version'
@@ -1,13 +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
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
@@ -1,20 +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
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
@@ -1,44 +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
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
@@ -1,36 +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
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
@@ -1,23 +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
+ # 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
- # frozen_string_literal: true
2
-
3
- require 'rails_compatibility/active_record'
4
-
5
- class << RailsCompatibility
6
- if GTE_RAILS_4_0
7
- def unscope_where(relation)
8
- relation.unscope(:where)
9
- end
10
- else
11
- def unscope_where(relation)
12
- relation.dup.tap{|s| s.where_values = [] }
13
- end
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_compatibility/active_record'
4
+
5
+ class << RailsCompatibility
6
+ if GTE_RAILS_4_0
7
+ def unscope_where(relation)
8
+ relation.unscope(:where)
9
+ end
10
+ else
11
+ def unscope_where(relation)
12
+ relation.dup.tap{|s| s.where_values = [] }
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
- module RailsCompatibility
2
- VERSION = '0.0.5'
3
- end
1
+ module RailsCompatibility
2
+ VERSION = '0.0.6'
3
+ end
@@ -1,44 +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
- spec.add_development_dependency 'backports', '~> 3.15.0'
42
-
43
- spec.add_dependency 'activerecord', '>= 3'
44
- 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