Module: Goldiloader::Compatibility
- Defined in:
- lib/goldiloader/compatibility.rb
Constant Summary collapse
- ACTIVE_RECORD_VERSION =
::Gem::Version.new(::ActiveRecord::VERSION::STRING)
- RAILS_3 =
ACTIVE_RECORD_VERSION < ::Gem::Version.new('4')
- MASS_ASSIGNMENT_SECURITY =
RAILS_3 || defined?(::ActiveRecord::MassAssignmentSecurity)
- ASSOCIATION_FINDER_SQL =
ACTIVE_RECORD_VERSION < ::Gem::Version.new('4.1')
- UNSCOPE_QUERY_METHOD =
ACTIVE_RECORD_VERSION >= ::Gem::Version.new('4.1')
- JOINS_EAGER_LOADABLE =
ACTIVE_RECORD_VERSION >= ::Gem::Version.new('4.2')
- UNSCOPED_EAGER_LOADABLE =
ACTIVE_RECORD_VERSION >= ::Gem::Version.new('4.1.9')
Class Method Summary collapse
-
.alias_method_chain(klass, target, feature) {|aliased_target, punctuation| ... } ⇒ Object
Copied from Rails since it is deprecated in Rails 5.0.
- .association_finder_sql_enabled? ⇒ Boolean
- .joins_eager_loadable? ⇒ Boolean
- .mass_assignment_security_enabled? ⇒ Boolean
- .unscope_query_method_enabled? ⇒ Boolean
- .unscoped_eager_loadable? ⇒ Boolean
Class Method Details
.alias_method_chain(klass, target, feature) {|aliased_target, punctuation| ... } ⇒ Object
Copied from Rails since it is deprecated in Rails 5.0. Switch to using Module#prepend when we drop Ruby 1.9 support.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/goldiloader/compatibility.rb', line 40 def self.alias_method_chain(klass, target, feature) # Strip out punctuation on predicates, bang or writer methods since # e.g. target?_without_feature is not a valid method name. aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 yield(aliased_target, punctuation) if block_given? with_method = "#{aliased_target}_with_#{feature}#{punctuation}" without_method = "#{aliased_target}_without_#{feature}#{punctuation}" klass.send(:alias_method, without_method, target) klass.send(:alias_method, target, with_method) case when klass.public_method_defined?(without_method) klass.send(:public, target) when klass.protected_method_defined?(without_method) klass.send(:protected, target) when klass.private_method_defined?(without_method) klass.send(:private, target) end end |
.association_finder_sql_enabled? ⇒ Boolean
18 19 20 |
# File 'lib/goldiloader/compatibility.rb', line 18 def self.association_finder_sql_enabled? ASSOCIATION_FINDER_SQL end |
.joins_eager_loadable? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/goldiloader/compatibility.rb', line 26 def self.joins_eager_loadable? # Associations with joins were not eager loadable prior to Rails 4.2 due to # https://github.com/rails/rails/pull/17678 JOINS_EAGER_LOADABLE end |
.mass_assignment_security_enabled? ⇒ Boolean
14 15 16 |
# File 'lib/goldiloader/compatibility.rb', line 14 def self.mass_assignment_security_enabled? MASS_ASSIGNMENT_SECURITY end |
.unscope_query_method_enabled? ⇒ Boolean
22 23 24 |
# File 'lib/goldiloader/compatibility.rb', line 22 def self.unscope_query_method_enabled? UNSCOPE_QUERY_METHOD end |
.unscoped_eager_loadable? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/goldiloader/compatibility.rb', line 32 def self.unscoped_eager_loadable? # Unscoped associations weren't properly eager loaded until after Rails 4.1.9. # See https://github.com/rails/rails/issues/11036. UNSCOPED_EAGER_LOADABLE end |