diff options
author | Xavier Noria <fxn@hashref.com> | 2016-07-24 21:23:23 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-07-24 21:23:23 +0200 |
commit | 5a83f054244288032a7c41c13c870674e61b14ae (patch) | |
tree | 2c8a54524901499b140c28d6e6abe1a85d7b6e76 /activemodel | |
parent | 56527bb737eb5e1d5531cafe99ce91d025565ead (diff) | |
download | rails-5a83f054244288032a7c41c13c870674e61b14ae.tar.gz rails-5a83f054244288032a7c41c13c870674e61b14ae.tar.bz2 rails-5a83f054244288032a7c41c13c870674e61b14ae.zip |
systematic revision of =~ usage in AMo
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 5 | ||||
-rw-r--r-- | activemodel/lib/active_model/type/time.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/format.rb | 5 | ||||
-rw-r--r-- | activemodel/test/validators/email_validator.rb | 6 |
4 files changed, 11 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index cc6285f932..140eb9420e 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -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})" diff --git a/activemodel/lib/active_model/type/time.rb b/activemodel/lib/active_model/type/time.rb index 34e09f0aba..08d127d187 100644 --- a/activemodel/lib/active_model/type/time.rb +++ b/activemodel/lib/active_model/type/time.rb @@ -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}" diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index 46a2e54fba..70799aaf23 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -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 diff --git a/activemodel/test/validators/email_validator.rb b/activemodel/test/validators/email_validator.rb index cff47ac230..dda0c4773c 100644 --- a/activemodel/test/validators/email_validator.rb +++ b/activemodel/test/validators/email_validator.rb @@ -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
\ No newline at end of file +end |