mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
applies new string literal convention in activemodel/lib
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
This commit is contained in:
parent
9617db2078
commit
18a2513729
28 changed files with 77 additions and 77 deletions
|
@ -21,24 +21,24 @@
|
|||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
require 'active_support'
|
||||
require 'active_support/rails'
|
||||
require 'active_model/version'
|
||||
require "active_support"
|
||||
require "active_support/rails"
|
||||
require "active_model/version"
|
||||
|
||||
module ActiveModel
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :AttributeAssignment
|
||||
autoload :AttributeMethods
|
||||
autoload :BlockValidator, 'active_model/validator'
|
||||
autoload :BlockValidator, "active_model/validator"
|
||||
autoload :Callbacks
|
||||
autoload :Conversion
|
||||
autoload :Dirty
|
||||
autoload :EachValidator, 'active_model/validator'
|
||||
autoload :EachValidator, "active_model/validator"
|
||||
autoload :ForbiddenAttributesProtection
|
||||
autoload :Lint
|
||||
autoload :Model
|
||||
autoload :Name, 'active_model/naming'
|
||||
autoload :Name, "active_model/naming"
|
||||
autoload :Naming
|
||||
autoload :SecurePassword
|
||||
autoload :Serialization
|
||||
|
@ -49,9 +49,9 @@ module ActiveModel
|
|||
|
||||
eager_autoload do
|
||||
autoload :Errors
|
||||
autoload :RangeError, 'active_model/errors'
|
||||
autoload :StrictValidationFailed, 'active_model/errors'
|
||||
autoload :UnknownAttributeError, 'active_model/errors'
|
||||
autoload :RangeError, "active_model/errors"
|
||||
autoload :StrictValidationFailed, "active_model/errors"
|
||||
autoload :UnknownAttributeError, "active_model/errors"
|
||||
end
|
||||
|
||||
module Serializers
|
||||
|
@ -69,5 +69,5 @@ module ActiveModel
|
|||
end
|
||||
|
||||
ActiveSupport.on_load(:i18n) do
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
|
||||
I18n.load_path << File.dirname(__FILE__) + "/active_model/locale/en.yml"
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/hash/keys'
|
||||
require "active_support/core_ext/hash/keys"
|
||||
|
||||
module ActiveModel
|
||||
module AttributeAssignment
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'concurrent/map'
|
||||
require 'mutex_m'
|
||||
require 'active_support/core_ext/regexp'
|
||||
require "concurrent/map"
|
||||
require "mutex_m"
|
||||
require "active_support/core_ext/regexp"
|
||||
|
||||
module ActiveModel
|
||||
# Raised when an attribute is not defined.
|
||||
|
@ -394,7 +394,7 @@ module ActiveModel
|
|||
AttributeMethodMatch = Struct.new(:target, :attr_name, :method_name)
|
||||
|
||||
def initialize(options = {})
|
||||
@prefix, @suffix = options.fetch(:prefix, ''), options.fetch(:suffix, '')
|
||||
@prefix, @suffix = options.fetch(:prefix, ""), options.fetch(:suffix, "")
|
||||
@regex = /^(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})$/
|
||||
@method_missing_target = "#{@prefix}attribute#{@suffix}"
|
||||
@method_name = "#{prefix}%s#{suffix}"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/array/extract_options'
|
||||
require "active_support/core_ext/array/extract_options"
|
||||
|
||||
module ActiveModel
|
||||
# == Active \Model \Callbacks
|
||||
|
|
|
@ -69,7 +69,7 @@ module ActiveModel
|
|||
# person = Person.create(id: 1)
|
||||
# person.to_param # => "1"
|
||||
def to_param
|
||||
(persisted? && key = to_key) ? key.join('-') : nil
|
||||
(persisted? && key = to_key) ? key.join("-") : nil
|
||||
end
|
||||
|
||||
# Returns a +string+ identifying the path associated with the object.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'active_support/hash_with_indifferent_access'
|
||||
require 'active_support/core_ext/object/duplicable'
|
||||
require "active_support/hash_with_indifferent_access"
|
||||
require "active_support/core_ext/object/duplicable"
|
||||
|
||||
module ActiveModel
|
||||
# == Active \Model \Dirty
|
||||
|
@ -123,9 +123,9 @@ module ActiveModel
|
|||
private_constant :OPTION_NOT_GIVEN
|
||||
|
||||
included do
|
||||
attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
|
||||
attribute_method_suffix '_previously_changed?', '_previous_change'
|
||||
attribute_method_affix prefix: 'restore_', suffix: '!'
|
||||
attribute_method_suffix "_changed?", "_change", "_will_change!", "_was"
|
||||
attribute_method_suffix "_previously_changed?", "_previous_change"
|
||||
attribute_method_affix prefix: "restore_", suffix: "!"
|
||||
end
|
||||
|
||||
# Returns +true+ if any of the attributes have unsaved changes, +false+ otherwise.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/array/conversions'
|
||||
require 'active_support/core_ext/string/inflections'
|
||||
require 'active_support/core_ext/object/deep_dup'
|
||||
require 'active_support/core_ext/string/filters'
|
||||
require "active_support/core_ext/array/conversions"
|
||||
require "active_support/core_ext/string/inflections"
|
||||
require "active_support/core_ext/object/deep_dup"
|
||||
require "active_support/core_ext/string/filters"
|
||||
|
||||
module ActiveModel
|
||||
# == Active \Model \Errors
|
||||
|
@ -437,7 +437,7 @@ module ActiveModel
|
|||
# person.errors.full_message(:name, 'is invalid') # => "Name is invalid"
|
||||
def full_message(attribute, message)
|
||||
return message if attribute == :base
|
||||
attr_name = attribute.to_s.tr('.', '_').humanize
|
||||
attr_name = attribute.to_s.tr(".", "_").humanize
|
||||
attr_name = @base.class.human_attribute_name(attribute, default: attr_name)
|
||||
I18n.t(:"errors.format", {
|
||||
default: "%{attribute} %{message}",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/hash/except'
|
||||
require 'active_support/core_ext/module/introspection'
|
||||
require 'active_support/core_ext/module/remove_method'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require "active_support/core_ext/hash/except"
|
||||
require "active_support/core_ext/module/introspection"
|
||||
require "active_support/core_ext/module/remove_method"
|
||||
require "active_support/core_ext/module/delegation"
|
||||
|
||||
module ActiveModel
|
||||
class Name
|
||||
|
@ -149,7 +149,7 @@ module ActiveModel
|
|||
|
||||
raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if @name.blank?
|
||||
|
||||
@unnamespaced = @name.sub(/^#{namespace.name}::/, '') if namespace
|
||||
@unnamespaced = @name.sub(/^#{namespace.name}::/, "") if namespace
|
||||
@klass = klass
|
||||
@singular = _singularize(@name)
|
||||
@plural = ActiveSupport::Inflector.pluralize(@singular)
|
||||
|
@ -192,7 +192,7 @@ module ActiveModel
|
|||
private
|
||||
|
||||
def _singularize(string)
|
||||
ActiveSupport::Inflector.underscore(string).tr('/'.freeze, '_'.freeze)
|
||||
ActiveSupport::Inflector.underscore(string).tr("/".freeze, "_".freeze)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ module ActiveModel
|
|||
# This is to avoid ActiveModel (and by extension the entire framework)
|
||||
# being dependent on a binary library.
|
||||
begin
|
||||
require 'bcrypt'
|
||||
require "bcrypt"
|
||||
rescue LoadError
|
||||
$stderr.puts "You don't have bcrypt installed in your application. Please add it to your Gemfile and run bundle install"
|
||||
raise
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'active_support/core_ext/hash/except'
|
||||
require 'active_support/core_ext/hash/slice'
|
||||
require "active_support/core_ext/hash/except"
|
||||
require "active_support/core_ext/hash/slice"
|
||||
|
||||
module ActiveModel
|
||||
# == Active \Model \Serialization
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/json'
|
||||
require "active_support/json"
|
||||
|
||||
module ActiveModel
|
||||
module Serializers
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
require 'active_model/type/helpers'
|
||||
require 'active_model/type/value'
|
||||
require "active_model/type/helpers"
|
||||
require "active_model/type/value"
|
||||
|
||||
require 'active_model/type/big_integer'
|
||||
require 'active_model/type/binary'
|
||||
require 'active_model/type/boolean'
|
||||
require 'active_model/type/date'
|
||||
require 'active_model/type/date_time'
|
||||
require 'active_model/type/decimal'
|
||||
require 'active_model/type/decimal_without_scale'
|
||||
require 'active_model/type/float'
|
||||
require 'active_model/type/immutable_string'
|
||||
require 'active_model/type/integer'
|
||||
require 'active_model/type/string'
|
||||
require 'active_model/type/text'
|
||||
require 'active_model/type/time'
|
||||
require 'active_model/type/unsigned_integer'
|
||||
require "active_model/type/big_integer"
|
||||
require "active_model/type/binary"
|
||||
require "active_model/type/boolean"
|
||||
require "active_model/type/date"
|
||||
require "active_model/type/date_time"
|
||||
require "active_model/type/decimal"
|
||||
require "active_model/type/decimal_without_scale"
|
||||
require "active_model/type/float"
|
||||
require "active_model/type/immutable_string"
|
||||
require "active_model/type/integer"
|
||||
require "active_model/type/string"
|
||||
require "active_model/type/text"
|
||||
require "active_model/type/time"
|
||||
require "active_model/type/unsigned_integer"
|
||||
|
||||
require 'active_model/type/registry'
|
||||
require "active_model/type/registry"
|
||||
|
||||
module ActiveModel
|
||||
module Type
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_model/type/integer'
|
||||
require "active_model/type/integer"
|
||||
|
||||
module ActiveModel
|
||||
module Type
|
||||
|
|
|
@ -38,7 +38,7 @@ module ActiveModel
|
|||
alias_method :to_str, :to_s
|
||||
|
||||
def hex
|
||||
@value.unpack('H*')[0]
|
||||
@value.unpack("H*")[0]
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
|
|
@ -12,7 +12,7 @@ module ActiveModel
|
|||
# - Empty strings are coerced to +nil+
|
||||
# - All other values will be coerced to +true+
|
||||
class Boolean < Value
|
||||
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
|
||||
FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
|
||||
|
||||
def type # :nodoc:
|
||||
:boolean
|
||||
|
@ -21,7 +21,7 @@ module ActiveModel
|
|||
private
|
||||
|
||||
def cast_value(value)
|
||||
if value == ''
|
||||
if value == ""
|
||||
nil
|
||||
else
|
||||
!FALSE_VALUES.include?(value)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_model/type/big_integer'
|
||||
require "active_model/type/big_integer"
|
||||
|
||||
module ActiveModel
|
||||
module Type
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_model/type/helpers/accepts_multiparameter_time'
|
||||
require 'active_model/type/helpers/numeric'
|
||||
require 'active_model/type/helpers/mutable'
|
||||
require 'active_model/type/helpers/time_value'
|
||||
require "active_model/type/helpers/accepts_multiparameter_time"
|
||||
require "active_model/type/helpers/numeric"
|
||||
require "active_model/type/helpers/mutable"
|
||||
require "active_model/type/helpers/time_value"
|
||||
|
|
|
@ -19,7 +19,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def is_utc?
|
||||
::Time.zone_default.nil? || ::Time.zone_default =~ 'UTC'
|
||||
::Time.zone_default.nil? || ::Time.zone_default =~ "UTC"
|
||||
end
|
||||
|
||||
def default_timezone
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_model/type/string'
|
||||
require "active_model/type/string"
|
||||
|
||||
module ActiveModel
|
||||
module Type
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveModel
|
|||
return value unless value.is_a?(::String)
|
||||
return if value.empty?
|
||||
|
||||
if value.start_with?('2000-01-01')
|
||||
if value.start_with?("2000-01-01")
|
||||
dummy_time_value = value
|
||||
else
|
||||
dummy_time_value = "2000-01-01 #{value}"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/hash/keys'
|
||||
require 'active_support/core_ext/hash/except'
|
||||
require "active_support/core_ext/array/extract_options"
|
||||
require "active_support/core_ext/hash/keys"
|
||||
require "active_support/core_ext/hash/except"
|
||||
|
||||
module ActiveModel
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ module ActiveModel
|
|||
private
|
||||
|
||||
def convert_to_reader_name(method_name)
|
||||
method_name.to_s.chomp('=')
|
||||
method_name.to_s.chomp("=")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/range'
|
||||
require "active_support/core_ext/range"
|
||||
|
||||
module ActiveModel
|
||||
module Validations
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/regexp'
|
||||
require "active_support/core_ext/regexp"
|
||||
|
||||
module ActiveModel
|
||||
module Validations
|
||||
|
|
|
@ -46,7 +46,7 @@ module ActiveModel
|
|||
keys = CHECKS.keys & options.keys
|
||||
|
||||
if keys.empty?
|
||||
raise ArgumentError, 'Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.'
|
||||
raise ArgumentError, "Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option."
|
||||
end
|
||||
|
||||
keys.each do |key|
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_support/core_ext/hash/slice'
|
||||
require "active_support/core_ext/hash/slice"
|
||||
|
||||
module ActiveModel
|
||||
module Validations
|
||||
|
@ -115,7 +115,7 @@ module ActiveModel
|
|||
key = "#{key.to_s.camelize}Validator"
|
||||
|
||||
begin
|
||||
validator = key.include?('::'.freeze) ? key.constantize : const_get(key)
|
||||
validator = key.include?("::".freeze) ? key.constantize : const_get(key)
|
||||
rescue NameError
|
||||
raise ArgumentError, "Unknown validator: '#{key}'"
|
||||
end
|
||||
|
|
|
@ -100,7 +100,7 @@ module ActiveModel
|
|||
# PresenceValidator.kind # => :presence
|
||||
# UniquenessValidator.kind # => :uniqueness
|
||||
def self.kind
|
||||
@kind ||= name.split('::').last.underscore.chomp('_validator').to_sym unless anonymous?
|
||||
@kind ||= name.split("::").last.underscore.chomp("_validator").to_sym unless anonymous?
|
||||
end
|
||||
|
||||
# Accepts options that will be made available through the +options+ reader.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative 'gem_version'
|
||||
require_relative "gem_version"
|
||||
|
||||
module ActiveModel
|
||||
# Returns the version of the currently loaded \Active \Model as a <tt>Gem::Version</tt>
|
||||
|
|
Loading…
Reference in a new issue