Skip to content

Commit

Permalink
Use constants instead of variables and assign value when the module f…
Browse files Browse the repository at this point in the history
…ile is loaded
  • Loading branch information
Jon Calvert committed Apr 14, 2015
1 parent 1ebf793 commit 5db5b31
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/goldiloader/compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
module Goldiloader
module Compatibility

MASS_ASSIGNMENT_SECURITY = (::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity))
ASSOCIATION_FINDER_SQL = (::Gem::Version.new(::ActiveRecord::VERSION::STRING) < ::Gem::Version.new('4.1'))
UNSCOPE_QUERY_METHOD = (::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new('4.1'))

def self.mass_assignment_security_enabled?
@mass_assignment_security_enabled = (::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity)) unless defined?(@mass_assignment_security_enabled)
@mass_assignment_security_enabled
MASS_ASSIGNMENT_SECURITY
end

def self.association_finder_sql_enabled?
@association_finder_sql = (::Gem::Version.new(::ActiveRecord::VERSION::STRING) < ::Gem::Version.new('4.1')) unless defined?(@association_finder_sql)
@association_finder_sql
ASSOCIATION_FINDER_SQL
end

def self.unscope_query_method_enabled?
@unscope_query_method = (::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new('4.1')) unless defined?(@unscope_query_method)
@unscope_query_method
UNSCOPE_QUERY_METHOD
end
end
end

0 comments on commit 5db5b31

Please sign in to comment.