rails_compatibility 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,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
- # frozen_string_literal: true
2
-
3
- require 'rails_compatibility/active_record'
4
-
5
- class << RailsCompatibility
6
- if ActiveRecord::VERSION::MAJOR < 4
7
- def unscope_where(relation)
8
- relation.dup.tap{|s| s.where_values = [] }
9
- end
10
- else
11
- def unscope_where(relation)
12
- relation.unscope(:where)
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.4'
3
- end
1
+ module RailsCompatibility
2
+ VERSION = '0.0.5'
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
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-10 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/rails_compatibility/attribute_types.rb
132
132
  - lib/rails_compatibility/build_joins.rb
133
133
  - lib/rails_compatibility/construct_join_dependency.rb
134
+ - lib/rails_compatibility/pick.rb
134
135
  - lib/rails_compatibility/unscope_where.rb
135
136
  - lib/rails_compatibility/version.rb
136
137
  - rails_compatibility.gemspec
@@ -143,7 +144,7 @@ metadata:
143
144
  source_code_uri: https://github.com/khiav223577/rails_compatibility
144
145
  documentation_uri: https://www.rubydoc.info/gems/rails_compatibility
145
146
  bug_tracker_uri: https://github.com/khiav223577/rails_compatibility/issues
146
- post_install_message:
147
+ post_install_message:
147
148
  rdoc_options: []
148
149
  require_paths:
149
150
  - lib
@@ -158,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  - !ruby/object:Gem::Version
159
160
  version: '0'
160
161
  requirements: []
161
- rubygems_version: 3.2.14
162
- signing_key:
162
+ rubygems_version: 3.1.4
163
+ signing_key:
163
164
  specification_version: 4
164
165
  summary: Provides cross-rails methods for you to upgrade rails, backport features,
165
166
  create easy-to-maintain gems, and so on.