mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
systematic revision of =~ usage in AMo
This commit is contained in:
parent
56527bb737
commit
5a83f05424
4 changed files with 11 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'concurrent/map'
|
||||
require 'mutex_m'
|
||||
require 'active_support/core_ext/regexp'
|
||||
|
||||
module ActiveModel
|
||||
# Raised when an attribute is not defined.
|
||||
|
@ -366,7 +367,7 @@ module ActiveModel
|
|||
# using the given `extra` args. This falls back on `define_method`
|
||||
# and `send` if the given names cannot be compiled.
|
||||
def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
|
||||
defn = if name =~ NAME_COMPILABLE_REGEXP
|
||||
defn = if NAME_COMPILABLE_REGEXP.match?(name)
|
||||
"def #{name}(*args)"
|
||||
else
|
||||
"define_method(:'#{name}') do |*args|"
|
||||
|
@ -374,7 +375,7 @@ module ActiveModel
|
|||
|
||||
extra = (extra.map!(&:inspect) << "*args").join(", ".freeze)
|
||||
|
||||
target = if send =~ CALL_COMPILABLE_REGEXP
|
||||
target = if CALL_COMPILABLE_REGEXP.match?(send)
|
||||
"#{"self." unless include_private}#{send}(#{extra})"
|
||||
else
|
||||
"send(:'#{send}', #{extra})"
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveModel
|
|||
return value unless value.is_a?(::String)
|
||||
return if value.empty?
|
||||
|
||||
if value =~ /^2000-01-01/
|
||||
if value.start_with?('2000-01-01')
|
||||
dummy_time_value = value
|
||||
else
|
||||
dummy_time_value = "2000-01-01 #{value}"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module ActiveModel
|
||||
require 'active_support/core_ext/regexp'
|
||||
|
||||
module ActiveModel
|
||||
module Validations
|
||||
class FormatValidator < EachValidator # :nodoc:
|
||||
def validate_each(record, attribute, value)
|
||||
|
@ -8,7 +9,7 @@ module ActiveModel
|
|||
record_error(record, attribute, :with, value) if value.to_s !~ regexp
|
||||
elsif options[:without]
|
||||
regexp = option_call(record, :without)
|
||||
record_error(record, attribute, :without, value) if value.to_s =~ regexp
|
||||
record_error(record, attribute, :without, value) if regexp.match?(value.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'active_support/core_ext/regexp'
|
||||
|
||||
class EmailValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
record.errors[attribute] << (options[:message] || "is not an email") unless
|
||||
value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.match?(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue