mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
clearing up many warnings, removing unnecessary regular expresion comparisons [#4365 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
b7d8f5a329
commit
61355c0e24
4 changed files with 25 additions and 26 deletions
|
@ -32,7 +32,6 @@ module ActiveRecord
|
||||||
# Enable the query cache within the block.
|
# Enable the query cache within the block.
|
||||||
def cache
|
def cache
|
||||||
old, @query_cache_enabled = @query_cache_enabled, true
|
old, @query_cache_enabled = @query_cache_enabled, true
|
||||||
@query_cache ||= {}
|
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
clear_query_cache
|
clear_query_cache
|
||||||
|
@ -54,7 +53,7 @@ module ActiveRecord
|
||||||
# the same SQL query and repeatedly return the same result each time, silently
|
# the same SQL query and repeatedly return the same result each time, silently
|
||||||
# undermining the randomness you were expecting.
|
# undermining the randomness you were expecting.
|
||||||
def clear_query_cache
|
def clear_query_cache
|
||||||
@query_cache.clear if @query_cache
|
@query_cache.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_all_with_query_cache(*args)
|
def select_all_with_query_cache(*args)
|
||||||
|
|
|
@ -41,6 +41,7 @@ module ActiveRecord
|
||||||
@connection, @logger = connection, logger
|
@connection, @logger = connection, logger
|
||||||
@runtime = 0
|
@runtime = 0
|
||||||
@query_cache_enabled = false
|
@query_cache_enabled = false
|
||||||
|
@query_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the human-readable name of the adapter. Use mixed case - one
|
# Returns the human-readable name of the adapter. Use mixed case - one
|
||||||
|
|
|
@ -54,6 +54,12 @@ module ActiveRecord
|
||||||
super(name, self.class.extract_value_from_default(default), sql_type, null)
|
super(name, self.class.extract_value_from_default(default), sql_type, null)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
|
class << self
|
||||||
|
attr_accessor :money_precision
|
||||||
|
end
|
||||||
|
# :startdoc:
|
||||||
|
|
||||||
private
|
private
|
||||||
def extract_limit(sql_type)
|
def extract_limit(sql_type)
|
||||||
case sql_type
|
case sql_type
|
||||||
|
@ -71,9 +77,11 @@ module ActiveRecord
|
||||||
|
|
||||||
# Extracts the precision from PostgreSQL-specific data types.
|
# Extracts the precision from PostgreSQL-specific data types.
|
||||||
def extract_precision(sql_type)
|
def extract_precision(sql_type)
|
||||||
# Actual code is defined dynamically in PostgreSQLAdapter.connect
|
if sql_type == 'money'
|
||||||
# depending on the server specifics
|
self.class.money_precision
|
||||||
super
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Maps PostgreSQL-specific data types to logical Rails types.
|
# Maps PostgreSQL-specific data types to logical Rails types.
|
||||||
|
@ -83,18 +91,18 @@ module ActiveRecord
|
||||||
when /^(?:real|double precision)$/
|
when /^(?:real|double precision)$/
|
||||||
:float
|
:float
|
||||||
# Monetary types
|
# Monetary types
|
||||||
when /^money$/
|
when 'money'
|
||||||
:decimal
|
:decimal
|
||||||
# Character types
|
# Character types
|
||||||
when /^(?:character varying|bpchar)(?:\(\d+\))?$/
|
when /^(?:character varying|bpchar)(?:\(\d+\))?$/
|
||||||
:string
|
:string
|
||||||
# Binary data types
|
# Binary data types
|
||||||
when /^bytea$/
|
when 'bytea'
|
||||||
:binary
|
:binary
|
||||||
# Date/time types
|
# Date/time types
|
||||||
when /^timestamp with(?:out)? time zone$/
|
when /^timestamp with(?:out)? time zone$/
|
||||||
:datetime
|
:datetime
|
||||||
when /^interval$/
|
when 'interval'
|
||||||
:string
|
:string
|
||||||
# Geometric types
|
# Geometric types
|
||||||
when /^(?:point|line|lseg|box|"?path"?|polygon|circle)$/
|
when /^(?:point|line|lseg|box|"?path"?|polygon|circle)$/
|
||||||
|
@ -106,16 +114,16 @@ module ActiveRecord
|
||||||
when /^bit(?: varying)?(?:\(\d+\))?$/
|
when /^bit(?: varying)?(?:\(\d+\))?$/
|
||||||
:string
|
:string
|
||||||
# XML type
|
# XML type
|
||||||
when /^xml$/
|
when 'xml'
|
||||||
:xml
|
:xml
|
||||||
# Arrays
|
# Arrays
|
||||||
when /^\D+\[\]$/
|
when /^\D+\[\]$/
|
||||||
:string
|
:string
|
||||||
# Object identifier types
|
# Object identifier types
|
||||||
when /^oid$/
|
when 'oid'
|
||||||
:integer
|
:integer
|
||||||
# UUID type
|
# UUID type
|
||||||
when /^uuid$/
|
when 'uuid'
|
||||||
:string
|
:string
|
||||||
# Small and big integer types
|
# Small and big integer types
|
||||||
when /^(?:small|big)int$/
|
when /^(?:small|big)int$/
|
||||||
|
@ -383,9 +391,9 @@ module ActiveRecord
|
||||||
def quote(value, column = nil) #:nodoc:
|
def quote(value, column = nil) #:nodoc:
|
||||||
if value.kind_of?(String) && column && column.type == :binary
|
if value.kind_of?(String) && column && column.type == :binary
|
||||||
"#{quoted_string_prefix}'#{escape_bytea(value)}'"
|
"#{quoted_string_prefix}'#{escape_bytea(value)}'"
|
||||||
elsif value.kind_of?(String) && column && column.sql_type =~ /^xml$/
|
elsif value.kind_of?(String) && column && column.sql_type == 'xml'
|
||||||
"xml E'#{quote_string(value)}'"
|
"xml E'#{quote_string(value)}'"
|
||||||
elsif value.kind_of?(Numeric) && column && column.sql_type =~ /^money$/
|
elsif value.kind_of?(Numeric) && column && column.sql_type == 'money'
|
||||||
# Not truly string input, so doesn't require (or allow) escape string syntax.
|
# Not truly string input, so doesn't require (or allow) escape string syntax.
|
||||||
"'#{value.to_s}'"
|
"'#{value.to_s}'"
|
||||||
elsif value.kind_of?(String) && column && column.sql_type =~ /^bit/
|
elsif value.kind_of?(String) && column && column.sql_type =~ /^bit/
|
||||||
|
@ -925,7 +933,7 @@ module ActiveRecord
|
||||||
# Construct a clean list of column names from the ORDER BY clause, removing
|
# Construct a clean list of column names from the ORDER BY clause, removing
|
||||||
# any ASC/DESC modifiers
|
# any ASC/DESC modifiers
|
||||||
order_columns = order_by.split(',').collect { |s| s.split.first }
|
order_columns = order_by.split(',').collect { |s| s.split.first }
|
||||||
order_columns.delete_if &:blank?
|
order_columns.delete_if(&:blank?)
|
||||||
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
|
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
|
||||||
|
|
||||||
# Return a DISTINCT ON() clause that's distinct on the columns we want but includes
|
# Return a DISTINCT ON() clause that's distinct on the columns we want but includes
|
||||||
|
@ -989,17 +997,8 @@ module ActiveRecord
|
||||||
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
|
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
|
||||||
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
|
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
|
||||||
# should know about this but can't detect it there, so deal with it here.
|
# should know about this but can't detect it there, so deal with it here.
|
||||||
money_precision = (postgresql_version >= 80300) ? 19 : 10
|
PostgreSQLColumn.money_precision =
|
||||||
PostgreSQLColumn.module_eval(<<-end_eval)
|
(postgresql_version >= 80300) ? 19 : 10
|
||||||
def extract_precision(sql_type) # def extract_precision(sql_type)
|
|
||||||
if sql_type =~ /^money$/ # if sql_type =~ /^money$/
|
|
||||||
#{money_precision} # 19
|
|
||||||
else # else
|
|
||||||
super # super
|
|
||||||
end # end
|
|
||||||
end # end
|
|
||||||
end_eval
|
|
||||||
|
|
||||||
configure_connection
|
configure_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_money_values
|
def test_money_values
|
||||||
assert_equal 567.89, @first_money.wealth
|
assert_equal 567.89, @first_money.wealth
|
||||||
assert_equal -567.89, @second_money.wealth
|
assert_equal(-567.89, @second_money.wealth)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_values
|
def test_number_values
|
||||||
|
|
Loading…
Reference in a new issue