diff options
Diffstat (limited to 'activesupport/lib/active_support')
42 files changed, 80 insertions, 73 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ad02546755..02218b8eaa 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -533,7 +533,7 @@ module ActiveSupport key = key.first end when Hash - key = key.sort_by { |k,_| k.to_s }.collect { |k,v| "#{k}=#{v}" } + key = key.sort_by { |k, _| k.to_s }.collect { |k, v| "#{k}=#{v}" } end key.to_param diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index cfd5e39bc4..00f4480308 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -110,7 +110,7 @@ module ActiveSupport # operator and can only be used on values written with the :raw option. # Calling it on a value not stored with :raw will initialize that value # to zero. - def increment(name, amount = 1, options = nil) # :nodoc: + def increment(name, amount = 1, options = nil) options = merged_options(options) instrument(:increment, name, amount: amount) do rescue_error_with nil do @@ -123,7 +123,7 @@ module ActiveSupport # operator and can only be used on values written with the :raw option. # Calling it on a value not stored with :raw will initialize that value # to zero. - def decrement(name, amount = 1, options = nil) # :nodoc: + def decrement(name, amount = 1, options = nil) options = merged_options(options) instrument(:decrement, name, amount: amount) do rescue_error_with nil do diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index 1a8477f9fe..968e72d765 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -57,7 +57,7 @@ module ActiveSupport start_time = Time.now cleanup instrument(:prune, target_size, from: @cache_size) do - keys = synchronize { @key_access.keys.sort { |a,b| @key_access[a].to_f <=> @key_access[b].to_f } } + keys = synchronize { @key_access.keys.sort { |a, b| @key_access[a].to_f <=> @key_access[b].to_f } } keys.each do |key| delete_entry(key, options) return if @cache_size <= target_size || (max_time && Time.now - start_time > max_time) diff --git a/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb b/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb index af51f66dda..174cb72b1e 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb @@ -12,9 +12,9 @@ module ActiveSupport attr_reader :name, :local_cache_key def initialize(name, local_cache_key) - @name = name + @name = name @local_cache_key = local_cache_key - @app = nil + @app = nil end def new(app) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 2ad1145fae..af8ddb176f 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -293,7 +293,7 @@ module ActiveSupport attr_reader :chain_config def initialize(name, filter, kind, options, chain_config) - @chain_config = chain_config + @chain_config = chain_config @name = name @kind = kind @filter = filter diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index 44ae96dbe8..d9b3743858 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -64,7 +64,7 @@ class DateTime # # => Sun, 01 Jan 2012 00:00:00 +0300 # DateTime.civil_from_format :local, 2012, 12, 17 # # => Mon, 17 Dec 2012 00:00:00 +0000 - def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0) + def self.civil_from_format(utc_or_local, year, month = 1, day = 1, hour = 0, min = 0, sec = 0) if utc_or_local.to_sym == :local offset = ::Time.local(year, month, day).utc_offset.to_r / 86400 else diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 3cd96ccb9a..2a58a7f1ca 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -160,7 +160,7 @@ module ActiveSupport def normalize_keys(params) case params when Hash - Hash[params.map { |k,v| [k.to_s.tr("-", "_"), normalize_keys(v)] } ] + Hash[params.map { |k, v| [k.to_s.tr("-", "_"), normalize_keys(v)] } ] when Array params.map { |v| normalize_keys(v) } else @@ -187,7 +187,7 @@ module ActiveSupport end if become_array?(value) - _, entries = Array.wrap(value.detect { |k,v| not v.is_a?(String) }) + _, entries = Array.wrap(value.detect { |k, v| not v.is_a?(String) }) if entries.nil? || value["__content__"].try(:empty?) [] else @@ -206,7 +206,7 @@ module ActiveSupport elsif become_empty_string?(value) "" elsif become_hash?(value) - xml_value = Hash[value.map { |k,v| [k, deep_to_h(v)] }] + xml_value = Hash[value.map { |k, v| [k, deep_to_h(v)] }] # Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with # how multipart uploaded files from HTML appear diff --git a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb index db3e7508e7..efb9d1b8a0 100644 --- a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb @@ -16,7 +16,7 @@ class Hash # Destructive +reverse_merge+. def reverse_merge!(other_hash) # right wins if there is no left - merge!( other_hash ) { |key,left,right| left } + merge!(other_hash) { |key, left, right| left } end alias_method :reverse_update, :reverse_merge! end diff --git a/activesupport/lib/active_support/core_ext/module/qualified_const.rb b/activesupport/lib/active_support/core_ext/module/qualified_const.rb index 62f0687ae9..b9814e1dbe 100644 --- a/activesupport/lib/active_support/core_ext/module/qualified_const.rb +++ b/activesupport/lib/active_support/core_ext/module/qualified_const.rb @@ -26,7 +26,7 @@ end # Object.const_get('::String') raises NameError and so does qualified_const_get. #++ class Module - def qualified_const_defined?(path, search_parents=true) + def qualified_const_defined?(path, search_parents = true) ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) Module#qualified_const_defined? is deprecated in favour of the builtin Module#const_defined? and will be removed in Rails 5.1. diff --git a/activesupport/lib/active_support/core_ext/regexp.rb b/activesupport/lib/active_support/core_ext/regexp.rb index 062d568228..d77d01bf42 100644 --- a/activesupport/lib/active_support/core_ext/regexp.rb +++ b/activesupport/lib/active_support/core_ext/regexp.rb @@ -3,7 +3,7 @@ class Regexp #:nodoc: options & MULTILINE == MULTILINE end - def match?(string, pos=0) + def match?(string, pos = 0) !!match(string, pos) end unless //.respond_to?(:match?) end diff --git a/activesupport/lib/active_support/core_ext/securerandom.rb b/activesupport/lib/active_support/core_ext/securerandom.rb index 92392d1a92..b2e4fff79a 100644 --- a/activesupport/lib/active_support/core_ext/securerandom.rb +++ b/activesupport/lib/active_support/core_ext/securerandom.rb @@ -1,7 +1,7 @@ require "securerandom" module SecureRandom - BASE58_ALPHABET = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"] + BASE58_ALPHABET = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"] # SecureRandom.base58 generates a random base58 string. # # The argument _n_ specifies the length, of the random string to be generated. diff --git a/activesupport/lib/active_support/core_ext/string/indent.rb b/activesupport/lib/active_support/core_ext/string/indent.rb index e87f72fdbd..d7b58301d3 100644 --- a/activesupport/lib/active_support/core_ext/string/indent.rb +++ b/activesupport/lib/active_support/core_ext/string/indent.rb @@ -2,7 +2,7 @@ class String # Same as +indent+, except it indents the receiver in-place. # # Returns the indented string, or +nil+ if there was nothing to indent. - def indent!(amount, indent_string=nil, indent_empty_lines=false) + def indent!(amount, indent_string = nil, indent_empty_lines = false) indent_string = indent_string || self[/^[ \t]/] || " " re = indent_empty_lines ? /^/ : /^(?!$)/ gsub!(re, indent_string * amount) @@ -37,7 +37,7 @@ class String # "foo\n\nbar".indent(2) # => " foo\n\n bar" # "foo\n\nbar".indent(2, nil, true) # => " foo\n \n bar" # - def indent(amount, indent_string=nil, indent_empty_lines=false) + def indent(amount, indent_string = nil, indent_empty_lines = false) dup.tap { |_| _.indent!(amount, indent_string, indent_empty_lines) } end end diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 2b7e556ced..227c34b032 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -202,7 +202,7 @@ module ActiveSupport #:nodoc: def %(args) case args when Hash - escaped_args = Hash[args.map { |k,arg| [k, html_escape_interpolated_argument(arg)] }] + escaped_args = Hash[args.map { |k, arg| [k, html_escape_interpolated_argument(arg)] }] else escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) } end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 2cbfa14772..cbdcb86d6d 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -104,7 +104,7 @@ class Time raise ArgumentError, "Can't change both :nsec and :usec at the same time: #{options.inspect}" if options[:usec] new_usec = Rational(new_nsec, 1000) else - new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000)) + new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000)) end if utc? diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 216d52164e..cad0d6d2e9 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -108,7 +108,7 @@ module ActiveSupport #:nodoc: def initialize @watching = [] - @stack = Hash.new { |h,k| h[k] = [] } + @stack = Hash.new { |h, k| h[k] = [] } end def each(&block) diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 6ec0c3a70a..82322291d0 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -7,6 +7,8 @@ module ActiveSupport # # 1.month.ago # equivalent to Time.now.advance(months: -1) class Duration + EPOCH = ::Time.utc(2000) + attr_accessor :value, :parts autoload :ISO8601Parser, "active_support/duration/iso8601_parser" @@ -33,7 +35,7 @@ module ActiveSupport end def -@ #:nodoc: - Duration.new(-value, parts.map { |type,number| [type, -number] }) + Duration.new(-value, parts.map { |type, number| [type, -number] }) end def is_a?(klass) #:nodoc: @@ -119,7 +121,7 @@ module ActiveSupport def inspect #:nodoc: parts. - reduce(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }. + reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }. sort_by { |unit, _ | [:years, :months, :weeks, :days, :hours, :minutes, :seconds].index(unit) }. map { |unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" }. to_sentence(locale: ::I18n.default_locale) @@ -129,7 +131,7 @@ module ActiveSupport to_i end - def respond_to_missing?(method, include_private=false) #:nodoc: + def respond_to_missing?(method, include_private = false) #:nodoc: @value.respond_to?(method, include_private) end @@ -140,8 +142,7 @@ module ActiveSupport # If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+. def self.parse(iso8601duration) parts = ISO8601Parser.new(iso8601duration).parse! - time = ::Time.current - new(time.advance(parts) - time, parts) + new(EPOCH.advance(parts) - EPOCH, parts) end # Build ISO 8601 Duration string for this duration. @@ -155,7 +156,7 @@ module ActiveSupport protected def sum(sign, time = ::Time.current) #:nodoc: - parts.inject(time) do |t,(type,number)| + parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) diff --git a/activesupport/lib/active_support/duration/iso8601_serializer.rb b/activesupport/lib/active_support/duration/iso8601_serializer.rb index 542630b950..51d53e2f8d 100644 --- a/activesupport/lib/active_support/duration/iso8601_serializer.rb +++ b/activesupport/lib/active_support/duration/iso8601_serializer.rb @@ -26,7 +26,7 @@ module ActiveSupport if parts.key?(:seconds) time << "#{sprintf(@precision ? "%0.0#{@precision}f" : '%g', parts[:seconds])}S" end - output << "T#{time}" if time.present? + output << "T#{time}" unless time.empty? "#{sign}#{output}" end @@ -37,7 +37,7 @@ module ActiveSupport # Zero parts are removed as not significant. # If all parts are negative it will negate all of them and return minus as a sign. def normalize - parts = @duration.parts.each_with_object(Hash.new(0)) do |(k,v),p| + parts = @duration.parts.each_with_object(Hash.new(0)) do |(k, v), p| p[k] += v unless v.zero? end # If all parts are negative - let's make a negative duration diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 98aceabe21..2dbbfadac1 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -145,7 +145,7 @@ module ActiveSupport end def escape(key) - key.gsub(",",'\,') + key.gsub(",", '\,') end def compile_ext(array) diff --git a/activesupport/lib/active_support/gzip.rb b/activesupport/lib/active_support/gzip.rb index 4aee8dddba..84eef6a623 100644 --- a/activesupport/lib/active_support/gzip.rb +++ b/activesupport/lib/active_support/gzip.rb @@ -25,7 +25,7 @@ module ActiveSupport end # Compresses a string using gzip. - def self.compress(source, level=Zlib::DEFAULT_COMPRESSION, strategy=Zlib::DEFAULT_STRATEGY) + def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY) output = Stream.new gz = Zlib::GzipWriter.new(output, level, strategy) gz.write(source) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index d3bb5496bf..1bed489547 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -237,7 +237,7 @@ module ActiveSupport # Same semantics as +reverse_merge+ but modifies the receiver in-place. def reverse_merge!(other_hash) - replace(reverse_merge( other_hash )) + replace(reverse_merge(other_hash)) end # Replaces the contents of this hash with other_hash. diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index c80243c40a..ef3df1240d 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -207,7 +207,7 @@ module ActiveSupport def demodulize(path) path = path.to_s if i = path.rindex("::") - path[(i+2)..-1] + path[(i + 2)..-1] else path end @@ -366,7 +366,7 @@ module ActiveSupport return Regexp.escape(camel_cased_word) if parts.blank? - last = parts.pop + last = parts.pop parts.reverse.inject(last) do |acc, part| part.empty? ? acc : "#{part}(::#{acc})?" diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb index 1064398d8c..23ab804eb1 100644 --- a/activesupport/lib/active_support/key_generator.rb +++ b/activesupport/lib/active_support/key_generator.rb @@ -17,7 +17,7 @@ module ActiveSupport # Returns a derived key suitable for use. The default key_size is chosen # to be compatible with the default settings of ActiveSupport::MessageVerifier. # i.e. OpenSSL::Digest::SHA1#block_length - def generate_key(salt, key_size=64) + def generate_key(salt, key_size = 64) OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size) end end diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb index ae1897b886..720ed47331 100644 --- a/activesupport/lib/active_support/lazy_load_hooks.rb +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -23,8 +23,8 @@ module ActiveSupport module LazyLoadHooks def self.extended(base) # :nodoc: base.class_eval do - @load_hooks = Hash.new { |h,k| h[k] = [] } - @loaded = Hash.new { |h,k| h[k] = [] } + @load_hooks = Hash.new { |h, k| h[k] = [] } + @loaded = Hash.new { |h, k| h[k] = [] } end end diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index e5812d75d0..cb6ea095b8 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -99,7 +99,7 @@ module ActiveSupport # option is set to +true+, it also adds bold to the string. This is based # on the Highline implementation and will automatically append CLEAR to the # end of the returned String. - def color(text, color, bold=false) + def color(text, color, bold = false) return text unless colorize_logging color = self.class.const_get(color.upcase) if color.is_a?(Symbol) bold = bold ? BOLD : "" diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index a7e30632f6..953ee77c2a 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -58,7 +58,7 @@ module ActiveSupport def initialize(level = DEBUG) @flush_count = 0 @level = level - @logged = Hash.new { |h,k| h[k] = [] } + @logged = Hash.new { |h, k| h[k] = [] } end def method_missing(level, message = nil) diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 217919ccb8..7842264b39 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -52,9 +52,9 @@ module ActiveSupport pos = 0 marker = 0 eoc = codepoints.length - while(pos < eoc) + while (pos < eoc) pos += 1 - previous = codepoints[pos-1] + previous = codepoints[pos - 1] current = codepoints[pos] should_break = @@ -62,19 +62,19 @@ module ActiveSupport if previous == database.boundary[:cr] && current == database.boundary[:lf] false # GB4. (Control|CR|LF) ÷ - elsif previous && in_char_class?(previous, [:control,:cr,:lf]) + elsif previous && in_char_class?(previous, [:control, :cr, :lf]) true # GB5. ÷ (Control|CR|LF) - elsif in_char_class?(current, [:control,:cr,:lf]) + elsif in_char_class?(current, [:control, :cr, :lf]) true # GB6. L X (L|V|LV|LVT) - elsif database.boundary[:l] === previous && in_char_class?(current, [:l,:v,:lv,:lvt]) + elsif database.boundary[:l] === previous && in_char_class?(current, [:l, :v, :lv, :lvt]) false # GB7. (LV|V) X (V|T) - elsif in_char_class?(previous, [:lv,:v]) && in_char_class?(current, [:v,:t]) + elsif in_char_class?(previous, [:lv, :v]) && in_char_class?(current, [:v, :t]) false # GB8. (LVT|T) X (T) - elsif in_char_class?(previous, [:lvt,:t]) && database.boundary[:t] === current + elsif in_char_class?(previous, [:lvt, :t]) && database.boundary[:t] === current false # GB8a. Regional_Indicator X Regional_Indicator elsif database.boundary[:regional_indicator] === previous && database.boundary[:regional_indicator] === current @@ -94,7 +94,7 @@ module ActiveSupport end if should_break - unpacked << codepoints[marker..pos-1] + unpacked << codepoints[marker..pos - 1] marker = pos end end @@ -110,12 +110,12 @@ module ActiveSupport # Re-order codepoints so the string becomes canonical. def reorder_characters(codepoints) - length = codepoints.length- 1 + length = codepoints.length - 1 pos = 0 while pos < length do - cp1, cp2 = database.codepoints[codepoints[pos]], database.codepoints[codepoints[pos+1]] + cp1, cp2 = database.codepoints[codepoints[pos]], database.codepoints[codepoints[pos + 1]] if (cp1.combining_class > cp2.combining_class) && (cp2.combining_class > 0) - codepoints[pos..pos+1] = cp2.code, cp1.code + codepoints[pos..pos + 1] = cp2.code, cp1.code pos += (pos > 0 ? -1 : 1) else pos += 1 @@ -157,9 +157,9 @@ module ActiveSupport lindex = starter_char - HANGUL_LBASE # -- Hangul if 0 <= lindex && lindex < HANGUL_LCOUNT - vindex = codepoints[starter_pos+1] - HANGUL_VBASE rescue vindex = -1 + vindex = codepoints[starter_pos + 1] - HANGUL_VBASE rescue vindex = -1 if 0 <= vindex && vindex < HANGUL_VCOUNT - tindex = codepoints[starter_pos+2] - HANGUL_TBASE rescue tindex = -1 + tindex = codepoints[starter_pos + 2] - HANGUL_TBASE rescue tindex = -1 if 0 <= tindex && tindex < HANGUL_TCOUNT j = starter_pos + 2 eoa -= 2 @@ -251,7 +251,7 @@ module ActiveSupport # * <tt>form</tt> - The form you want to normalize in. Should be one of # the following: <tt>:c</tt>, <tt>:kc</tt>, <tt>:d</tt>, or <tt>:kd</tt>. # Default is ActiveSupport::Multibyte::Unicode.default_normalization_form. - def normalize(string, form=nil) + def normalize(string, form = nil) form ||= @default_normalization_form # See http://www.unicode.org/reports/tr15, Table 1 codepoints = string.codepoints.to_a diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 23262d5398..e11e2e0689 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -14,7 +14,7 @@ module ActiveSupport # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block. - def instrument(name, payload={}) + def instrument(name, payload = {}) # some of the listeners might have state listeners_state = start name, payload begin diff --git a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb index 695ee1dad3..56185ddf4b 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb @@ -18,7 +18,7 @@ module ActiveSupport units = opts[:units] exponent = calculate_exponent(units) - @number = number / (10 ** exponent) + @number = number / (10**exponent) until (rounded_number = NumberToRoundedConverter.convert(number, options)) != NumberToRoundedConverter.convert(1000, options) @number = number / 1000.0 diff --git a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb index 78cb33aa62..02b4231794 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb @@ -21,7 +21,7 @@ module ActiveSupport if smaller_than_base? number_to_format = number.to_i.to_s else - human_size = number / (base ** exponent) + human_size = number / (base**exponent) number_to_format = NumberToRoundedConverter.convert(human_size, options) end conversion_format.gsub("%n".freeze, number_to_format).gsub("%u".freeze, unit) diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb index c2612f9a9b..1de9f50f34 100644 --- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb @@ -2,7 +2,7 @@ module ActiveSupport module NumberHelper class NumberToPhoneConverter < NumberConverter #:nodoc: def convert - str = country_code(opts[:country_code]) + str = country_code(opts[:country_code]) str << convert_to_phone_number(number.to_s.strip) str << phone_ext(opts[:extension]) end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index cfcb0045fb..1f013990ea 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -52,7 +52,7 @@ module ActiveSupport [1, 0] else digits = digit_count(number) - multiplier = 10 ** (digits - precision) + multiplier = 10**(digits - precision) rounded_number = calculate_rounded_number(multiplier) digits = digit_count(rounded_number) # After rounding, the number of digits may have changed [digits, rounded_number] diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 793bc9e22d..3aa0a14f04 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -25,7 +25,7 @@ module ActiveSupport end def encode_with(coder) - coder.represent_seq "!omap", map { |k,v| { k => v } } + coder.represent_seq "!omap", map { |k, v| { k => v } } end def select(*args, &block) diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 14ed9049be..04d6dfaf9c 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -68,9 +68,9 @@ module ActiveSupport def initialize(parent = nil) if parent.kind_of?(OrderedOptions) # use the faster _get when dealing with OrderedOptions - super() { |h,k| parent._get(k) } + super() { |h, k| parent._get(k) } elsif parent - super() { |h,k| parent[k] } + super() { |h, k| parent[k] } else super() end diff --git a/activesupport/lib/active_support/rails.rb b/activesupport/lib/active_support/rails.rb index 57380061f7..f6b018f0d3 100644 --- a/activesupport/lib/active_support/rails.rb +++ b/activesupport/lib/active_support/rails.rb @@ -25,3 +25,9 @@ require "active_support/core_ext/module/delegation" # Defines ActiveSupport::Deprecation. require "active_support/deprecation" + +# Defines Regexp#match?. +# +# This should be removed when Rails needs Ruby 2.4 or later, and the require +# added where other Regexp extensions are being used (easy to grep). +require "active_support/core_ext/regexp" diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index 0f09f1eb63..c018d3e245 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/activesupport/lib/active_support/subscriber.rb @@ -24,7 +24,7 @@ module ActiveSupport class Subscriber class << self # Attach the subscriber to a namespace. - def attach_to(namespace, subscriber=new, notifier=ActiveSupport::Notifications) + def attach_to(namespace, subscriber = new, notifier = ActiveSupport::Notifications) @namespace = namespace @subscriber = subscriber @notifier = notifier diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb index 0bf3643a56..53ab3ebf78 100644 --- a/activesupport/lib/active_support/testing/declarative.rb +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -9,7 +9,7 @@ module ActiveSupport # ... # end def test(name, &block) - test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym + test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym defined = method_defined? test_name raise "#{test_name} is already defined in #{self}" if defined if block_given? diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index a562f33420..09cb9cbbe1 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -295,7 +295,7 @@ module ActiveSupport # zone = ActiveSupport::TimeZone['Central Time (US & Canada)'] # zone.formatted_offset # => "-06:00" # zone.formatted_offset(false) # => "-0600" - def formatted_offset(colon=true, alternate_utc_string = nil) + def formatted_offset(colon = true, alternate_utc_string = nil) utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon) end @@ -355,7 +355,7 @@ module ActiveSupport # components are supplied, then the day of the month defaults to 1: # # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00 - def parse(str, now=now()) + def parse(str, now = now()) parts_to_time(Date._parse(str, false), now) end @@ -379,7 +379,7 @@ module ActiveSupport # components are supplied, then the day of the month defaults to 1: # # Time.zone.strptime('Mar 2000', '%b %Y') # => Wed, 01 Mar 2000 00:00:00 HST -10:00 - def strptime(str, format, now=now()) + def strptime(str, format, now = now()) parts_to_time(DateTime._strptime(str, format), now) end @@ -416,7 +416,7 @@ module ActiveSupport # Adjust the given time to the simultaneous time in UTC. Returns a # Time.utc() instance. - def local_to_utc(time, dst=true) + def local_to_utc(time, dst = true) tzinfo.local_to_utc(time, dst) end @@ -428,7 +428,7 @@ module ActiveSupport # Available so that TimeZone instances respond like TZInfo::Timezone # instances. - def period_for_local(time, dst=true) + def period_for_local(time, dst = true) tzinfo.period_for_local(time, dst) end @@ -441,7 +441,7 @@ module ActiveSupport end def encode_with(coder) #:nodoc: - coder.tag ="!ruby/object:#{self.class}" + coder.tag = "!ruby/object:#{self.class}" coder.map = { "name" => tzinfo.name } end diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 921a3447d0..e16581d697 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -153,7 +153,7 @@ module ActiveSupport def _dasherize(key) # $2 must be a non-greedy regex for this to work - left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3] + left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3] "#{left}#{middle.tr('_ ', '--')}#{right}" end diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb index 10498c9be0..a7939b3185 100644 --- a/activesupport/lib/active_support/xml_mini/jdom.rb +++ b/activesupport/lib/active_support/xml_mini/jdom.rb @@ -141,7 +141,7 @@ module ActiveSupport attributes = element.attributes (0...attributes.length).each do |i| attribute_hash[CONTENT_KEY] ||= "" - attribute_hash[attributes.item(i).name] = attributes.item(i).value + attribute_hash[attributes.item(i).name] = attributes.item(i).value end attribute_hash end diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index 8a4aa03963..44b0bdb7dc 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -40,7 +40,7 @@ module LibXML #:nodoc: # # hash:: # Hash to merge the converted element into. - def to_hash(hash={}) + def to_hash(hash = {}) node_hash = {} # Insert node hash into parent hash correctly. diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index b92fa7ea7c..4c2be3f3ec 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -44,7 +44,7 @@ module ActiveSupport # # hash:: # Hash to merge the converted element into. - def to_hash(hash={}) + def to_hash(hash = {}) node_hash = {} # Insert node hash into parent hash correctly. diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb index 091a15294c..03fa910fa5 100644 --- a/activesupport/lib/active_support/xml_mini/rexml.rb +++ b/activesupport/lib/active_support/xml_mini/rexml.rb @@ -113,7 +113,7 @@ module ActiveSupport # XML element to extract attributes from. def get_attributes(element) attributes = {} - element.attributes.each { |n,v| attributes[n] = v } + element.attributes.each { |n, v| attributes[n] = v } attributes end |