mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix Remaining Case-In-Assignment Statement Formatting
Recently, the Rails team made an effort to keep the source code consistent, using Ruboco (bb1ecdcc67
and below). Some of the case statements were missed. This changes the case statements' formatting and is consistent with changes in810dff7c9f
anddb63406cb0
.
This commit is contained in:
parent
38fae35d53
commit
fbccae4d19
10 changed files with 123 additions and 113 deletions
|
@ -1026,15 +1026,16 @@ module ActionView
|
|||
# prompt_option_tag(:month, prompt: 'Select month')
|
||||
# => "<option value="">Select month</option>"
|
||||
def prompt_option_tag(type, options)
|
||||
prompt = case options
|
||||
when Hash
|
||||
default_options = { year: false, month: false, day: false, hour: false, minute: false, second: false }
|
||||
default_options.merge!(options)[type.to_sym]
|
||||
when String
|
||||
options
|
||||
prompt = \
|
||||
case options
|
||||
when Hash
|
||||
default_options = { year: false, month: false, day: false, hour: false, minute: false, second: false }
|
||||
default_options.merge!(options)[type.to_sym]
|
||||
when String
|
||||
options
|
||||
else
|
||||
I18n.translate(:"datetime.prompts.#{type}", locale: @options[:locale])
|
||||
end
|
||||
I18n.translate(:"datetime.prompts.#{type}", locale: @options[:locale])
|
||||
end
|
||||
|
||||
prompt ? content_tag("option".freeze, prompt, value: "") : ""
|
||||
end
|
||||
|
|
|
@ -857,23 +857,24 @@ module ActionView
|
|||
authenticity_token = html_options.delete("authenticity_token")
|
||||
method = html_options.delete("method").to_s.downcase
|
||||
|
||||
method_tag = case method
|
||||
when "get"
|
||||
html_options["method"] = "get"
|
||||
""
|
||||
when "post", ""
|
||||
html_options["method"] = "post"
|
||||
token_tag(authenticity_token, form_options: {
|
||||
action: html_options["action"],
|
||||
method: "post"
|
||||
})
|
||||
method_tag = \
|
||||
case method
|
||||
when "get"
|
||||
html_options["method"] = "get"
|
||||
""
|
||||
when "post", ""
|
||||
html_options["method"] = "post"
|
||||
token_tag(authenticity_token, form_options: {
|
||||
action: html_options["action"],
|
||||
method: "post"
|
||||
})
|
||||
else
|
||||
html_options["method"] = "post"
|
||||
method_tag(method) + token_tag(authenticity_token, form_options: {
|
||||
action: html_options["action"],
|
||||
method: method
|
||||
})
|
||||
end
|
||||
html_options["method"] = "post"
|
||||
method_tag(method) + token_tag(authenticity_token, form_options: {
|
||||
action: html_options["action"],
|
||||
method: method
|
||||
})
|
||||
end
|
||||
|
||||
if html_options.delete("enforce_utf8") { true }
|
||||
utf8_enforcer_tag + method_tag
|
||||
|
|
|
@ -16,18 +16,19 @@ module ActiveModel
|
|||
private
|
||||
|
||||
def cast_value(value)
|
||||
casted_value = case value
|
||||
when ::Float
|
||||
convert_float_to_big_decimal(value)
|
||||
when ::Numeric, ::String
|
||||
BigDecimal(value, precision.to_i)
|
||||
else
|
||||
if value.respond_to?(:to_d)
|
||||
value.to_d
|
||||
else
|
||||
cast_value(value.to_s)
|
||||
end
|
||||
end
|
||||
casted_value = \
|
||||
case value
|
||||
when ::Float
|
||||
convert_float_to_big_decimal(value)
|
||||
when ::Numeric, ::String
|
||||
BigDecimal(value, precision.to_i)
|
||||
else
|
||||
if value.respond_to?(:to_d)
|
||||
value.to_d
|
||||
else
|
||||
cast_value(value.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
apply_scale(casted_value)
|
||||
end
|
||||
|
|
|
@ -570,22 +570,23 @@ module ActiveRecord
|
|||
|
||||
# Maps logical Rails types to MySQL-specific data types.
|
||||
def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = nil)
|
||||
sql = case type.to_s
|
||||
when "integer"
|
||||
integer_to_sql(limit)
|
||||
when "text"
|
||||
text_to_sql(limit)
|
||||
when "blob"
|
||||
binary_to_sql(limit)
|
||||
when "binary"
|
||||
if (0..0xfff) === limit
|
||||
"varbinary(#{limit})"
|
||||
else
|
||||
binary_to_sql(limit)
|
||||
end
|
||||
else
|
||||
super(type, limit, precision, scale)
|
||||
end
|
||||
sql = \
|
||||
case type.to_s
|
||||
when "integer"
|
||||
integer_to_sql(limit)
|
||||
when "text"
|
||||
text_to_sql(limit)
|
||||
when "blob"
|
||||
binary_to_sql(limit)
|
||||
when "binary"
|
||||
if (0..0xfff) === limit
|
||||
"varbinary(#{limit})"
|
||||
else
|
||||
binary_to_sql(limit)
|
||||
end
|
||||
else
|
||||
super(type, limit, precision, scale)
|
||||
end
|
||||
|
||||
sql << " unsigned" if unsigned && type != :primary_key
|
||||
sql
|
||||
|
|
|
@ -625,31 +625,32 @@ module ActiveRecord
|
|||
|
||||
# Maps logical Rails types to PostgreSQL-specific data types.
|
||||
def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
|
||||
sql = case type.to_s
|
||||
when "binary"
|
||||
# PostgreSQL doesn't support limits on binary (bytea) columns.
|
||||
# The hard limit is 1GB, because of a 32-bit size field, and TOAST.
|
||||
case limit
|
||||
when nil, 0..0x3fffffff; super(type)
|
||||
else raise(ActiveRecordError, "No binary type has byte size #{limit}.")
|
||||
end
|
||||
when "text"
|
||||
# PostgreSQL doesn't support limits on text columns.
|
||||
# The hard limit is 1GB, according to section 8.3 in the manual.
|
||||
case limit
|
||||
when nil, 0..0x3fffffff; super(type)
|
||||
else raise(ActiveRecordError, "The limit on text can be at most 1GB - 1byte.")
|
||||
end
|
||||
when "integer"
|
||||
case limit
|
||||
when 1, 2; "smallint"
|
||||
when nil, 3, 4; "integer"
|
||||
when 5..8; "bigint"
|
||||
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with scale 0 instead.")
|
||||
end
|
||||
else
|
||||
super(type, limit, precision, scale)
|
||||
end
|
||||
sql = \
|
||||
case type.to_s
|
||||
when "binary"
|
||||
# PostgreSQL doesn't support limits on binary (bytea) columns.
|
||||
# The hard limit is 1GB, because of a 32-bit size field, and TOAST.
|
||||
case limit
|
||||
when nil, 0..0x3fffffff; super(type)
|
||||
else raise(ActiveRecordError, "No binary type has byte size #{limit}.")
|
||||
end
|
||||
when "text"
|
||||
# PostgreSQL doesn't support limits on text columns.
|
||||
# The hard limit is 1GB, according to section 8.3 in the manual.
|
||||
case limit
|
||||
when nil, 0..0x3fffffff; super(type)
|
||||
else raise(ActiveRecordError, "The limit on text can be at most 1GB - 1byte.")
|
||||
end
|
||||
when "integer"
|
||||
case limit
|
||||
when 1, 2; "smallint"
|
||||
when nil, 3, 4; "integer"
|
||||
when 5..8; "bigint"
|
||||
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with scale 0 instead.")
|
||||
end
|
||||
else
|
||||
super(type, limit, precision, scale)
|
||||
end
|
||||
|
||||
sql << "[]" if array && type != :primary_key
|
||||
sql
|
||||
|
|
|
@ -519,14 +519,15 @@ module ActiveRecord
|
|||
# larger than the limit.
|
||||
def check_record_limit!(limit, attributes_collection)
|
||||
if limit
|
||||
limit = case limit
|
||||
when Symbol
|
||||
send(limit)
|
||||
when Proc
|
||||
limit.call
|
||||
else
|
||||
limit
|
||||
end
|
||||
limit = \
|
||||
case limit
|
||||
when Symbol
|
||||
send(limit)
|
||||
when Proc
|
||||
limit.call
|
||||
else
|
||||
limit
|
||||
end
|
||||
|
||||
if limit && attributes_collection.size > limit
|
||||
raise TooManyRecords, "Maximum #{limit} records are allowed. Got #{attributes_collection.size} records instead."
|
||||
|
|
|
@ -59,11 +59,12 @@ module ActiveRecord
|
|||
FROZEN_EMPTY_HASH = {}.freeze
|
||||
|
||||
Relation::VALUE_METHODS.each do |name|
|
||||
method_name = case name
|
||||
when *Relation::MULTI_VALUE_METHODS then "#{name}_values"
|
||||
when *Relation::SINGLE_VALUE_METHODS then "#{name}_value"
|
||||
when *Relation::CLAUSE_METHODS then "#{name}_clause"
|
||||
end
|
||||
method_name = \
|
||||
case name
|
||||
when *Relation::MULTI_VALUE_METHODS then "#{name}_values"
|
||||
when *Relation::SINGLE_VALUE_METHODS then "#{name}_value"
|
||||
when *Relation::CLAUSE_METHODS then "#{name}_clause"
|
||||
end
|
||||
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
||||
def #{method_name} # def includes_values
|
||||
get_value(#{name.inspect}) # get_value(:includes)
|
||||
|
|
|
@ -46,14 +46,15 @@ module ActiveRecord
|
|||
def structure_dump(filename)
|
||||
set_psql_env
|
||||
|
||||
search_path = case ActiveRecord::Base.dump_schemas
|
||||
when :schema_search_path
|
||||
configuration["schema_search_path"]
|
||||
when :all
|
||||
nil
|
||||
when String
|
||||
ActiveRecord::Base.dump_schemas
|
||||
end
|
||||
search_path = \
|
||||
case ActiveRecord::Base.dump_schemas
|
||||
when :schema_search_path
|
||||
configuration["schema_search_path"]
|
||||
when :all
|
||||
nil
|
||||
when String
|
||||
ActiveRecord::Base.dump_schemas
|
||||
end
|
||||
|
||||
args = ["-s", "-x", "-O", "-f", filename]
|
||||
unless search_path.blank?
|
||||
|
|
|
@ -83,14 +83,15 @@ module I18n
|
|||
def self.init_fallbacks(fallbacks)
|
||||
include_fallbacks_module
|
||||
|
||||
args = case fallbacks
|
||||
when ActiveSupport::OrderedOptions
|
||||
[*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
|
||||
when Hash, Array
|
||||
Array.wrap(fallbacks)
|
||||
else # TrueClass
|
||||
[]
|
||||
end
|
||||
args = \
|
||||
case fallbacks
|
||||
when ActiveSupport::OrderedOptions
|
||||
[*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
|
||||
when Hash, Array
|
||||
Array.wrap(fallbacks)
|
||||
else # TrueClass
|
||||
[]
|
||||
end
|
||||
|
||||
I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
|
||||
end
|
||||
|
|
|
@ -162,14 +162,15 @@ module Rails
|
|||
|
||||
def set_default_accessors!
|
||||
self.destination_root = File.expand_path(app_path, destination_root)
|
||||
self.rails_template = case options[:template]
|
||||
when /^https?:\/\//
|
||||
options[:template]
|
||||
when String
|
||||
File.expand_path(options[:template], Dir.pwd)
|
||||
self.rails_template = \
|
||||
case options[:template]
|
||||
when /^https?:\/\//
|
||||
options[:template]
|
||||
when String
|
||||
File.expand_path(options[:template], Dir.pwd)
|
||||
else
|
||||
options[:template]
|
||||
end
|
||||
options[:template]
|
||||
end
|
||||
end
|
||||
|
||||
def database_gemfile_entry
|
||||
|
|
Loading…
Reference in a new issue