Module: RailsCompatibility
- Defined in:
- lib/rails_compatibility/version.rb
Constant Summary collapse
- VERSION =
'0.0.10'
- GTE_RAILS_7_0 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.0.0')
- GTE_RAILS_6_1 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.1.0')
- GTE_RAILS_6_0 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.0.0')
- GTE_RAILS_5_2 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.2.0')
- GTE_RAILS_5_1 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1.0')
- GTE_RAILS_5_0 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.0.0')
- GTE_RAILS_4_0 =
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('4.0.0')
Instance Method Summary collapse
- #apply_join_dependency(relation) ⇒ Object
-
#attribute_types(klass) ⇒ Object
In Rails 3.
- #build_joins(reflect, relation) ⇒ Object
-
#cast_values(klass, result) ⇒ Object
Rails 7.0.6 changes parameter handling.
- #construct_join_dependency(reflect, _relation) ⇒ Object
-
#deserialize(type, attribute) ⇒ Object
type_cast_from_database was changed to deserialize in Rails 5.
- #has_include?(relation, column_name) ⇒ Boolean
- #setup_autoload_paths(paths) ⇒ Object
- #unscope_where(relation) ⇒ Object
Instance Method Details
#apply_join_dependency(relation) ⇒ Object
8 9 10 |
# File 'lib/rails_compatibility/apply_join_dependency.rb', line 8 def apply_join_dependency(relation) relation.send(:apply_join_dependency) end |
#attribute_types(klass) ⇒ Object
In Rails 3
16 17 18 |
# File 'lib/rails_compatibility/attribute_types.rb', line 16 def attribute_types(klass) klass.attribute_types end |
#build_joins(reflect, relation) ⇒ Object
9 10 11 12 13 |
# File 'lib/rails_compatibility/build_joins.rb', line 9 def build_joins(reflect, relation) join_dependency = construct_join_dependency(reflect, relation) joins = join_dependency.join_constraints([], relation.alias_tracker, relation.references_values) return joins end |
#cast_values(klass, result) ⇒ Object
Rails 7.0.6 changes parameter handling. Details at: github.com/rails/rails/pull/45783
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rails_compatibility/cast_values.rb', line 11 def cast_values(klass, result) attribute_types = self.attribute_types(klass) result.map do |attributes| # This map behaves different to array#map attributes.each_with_index do |(key, attribute), index| attributes[key] = deserialize(result.send(:column_type, key, index, attribute_types), attribute) end next attributes end end |
#construct_join_dependency(reflect, _relation) ⇒ Object
8 9 10 11 |
# File 'lib/rails_compatibility/construct_join_dependency.rb', line 8 def construct_join_dependency(reflect, relation) joins = inverse_association_joins(reflect) return relation.construct_join_dependency(joins, Arel::Nodes::InnerJoin) end |
#deserialize(type, attribute) ⇒ Object
type_cast_from_database was changed to deserialize in Rails 5
9 10 11 |
# File 'lib/rails_compatibility/deserialize.rb', line 9 def deserialize(type, attribute) type.deserialize(attribute) end |
#has_include?(relation, column_name) ⇒ Boolean
8 9 10 |
# File 'lib/rails_compatibility/has_include.rb', line 8 def has_include?(relation, column_name) relation.send(:has_include?, column_name) end |
#setup_autoload_paths(paths) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rails_compatibility/setup_autoload_paths.rb', line 7 def setup_autoload_paths(paths) require 'zeitwerk' loader = Zeitwerk::Loader.new paths.each do |path| ActiveSupport::Dependencies.autoload_paths << path loader.push_dir(path) end loader.setup end |
#unscope_where(relation) ⇒ Object
7 8 9 |
# File 'lib/rails_compatibility/unscope_where.rb', line 7 def unscope_where(relation) relation.unscope(:where) end |