Merge pull request #9495 from Homebrew/dependabot/bundler/Library/Homebrew/activesupport-6.1.0

build(deps): bump activesupport from 6.0.3.4 to 6.1.0 in /Library/Homebrew
This commit is contained in:
Markus Reiter 2020-12-10 10:38:20 +01:00 committed by GitHub
commit e1451496c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
308 changed files with 10162 additions and 9612 deletions

View File

@ -1,12 +1,12 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
activesupport (6.0.3.4) activesupport (6.1.0)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 1.6, < 2)
minitest (~> 5.1) minitest (>= 5.1)
tzinfo (~> 1.1) tzinfo (~> 2.0)
zeitwerk (~> 2.2, >= 2.2.2) zeitwerk (~> 2.3)
ast (2.4.1) ast (2.4.1)
bindata (2.4.8) bindata (2.4.8)
byebug (11.1.3) byebug (11.1.3)
@ -151,9 +151,8 @@ GEM
spoom spoom
thor (>= 0.19.2) thor (>= 0.19.2)
thor (1.0.1) thor (1.0.1)
thread_safe (0.3.6) tzinfo (2.0.3)
tzinfo (1.2.8) concurrent-ruby (~> 1.0)
thread_safe (~> 0.1)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.7) unf_ext (0.0.7.7)

View File

@ -1,8 +0,0 @@
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `activesupport` gem.
# Please instead update this file by running `tapioca sync`.
# typed: false
# THIS IS AN EMPTY RBI FILE.
# see https://github.com/Shopify/tapioca/blob/master/README.md#manual-gem-requires

View File

@ -0,0 +1,608 @@
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `activesupport` gem.
# Please instead update this file by running `tapioca sync`.
# typed: false
module ActiveSupport
extend(::ActiveSupport::LazyLoadHooks)
end
module ActiveSupport::Inflector
extend(::ActiveSupport::Inflector)
def camelize(term, uppercase_first_letter = T.unsafe(nil)); end
def classify(table_name); end
def constantize(camel_cased_word); end
def dasherize(underscored_word); end
def deconstantize(path); end
def demodulize(path); end
def foreign_key(class_name, separate_class_name_and_id_with_underscore = T.unsafe(nil)); end
def humanize(lower_case_and_underscored_word, capitalize: T.unsafe(nil), keep_id_suffix: T.unsafe(nil)); end
def inflections(locale = T.unsafe(nil)); end
def ordinal(number); end
def ordinalize(number); end
def parameterize(string, separator: T.unsafe(nil), preserve_case: T.unsafe(nil), locale: T.unsafe(nil)); end
def pluralize(word, locale = T.unsafe(nil)); end
def safe_constantize(camel_cased_word); end
def singularize(word, locale = T.unsafe(nil)); end
def tableize(class_name); end
def titleize(word, keep_id_suffix: T.unsafe(nil)); end
def transliterate(string, replacement = T.unsafe(nil), locale: T.unsafe(nil)); end
def underscore(camel_cased_word); end
def upcase_first(string); end
private
def apply_inflections(word, rules, locale = T.unsafe(nil)); end
def const_regexp(camel_cased_word); end
end
ActiveSupport::Inflector::ALLOWED_ENCODINGS_FOR_TRANSLITERATE = T.let(T.unsafe(nil), Array)
class ActiveSupport::Inflector::Inflections
def initialize; end
def acronym(word); end
def acronyms; end
def acronyms_camelize_regex; end
def acronyms_underscore_regex; end
def clear(scope = T.unsafe(nil)); end
def human(rule, replacement); end
def humans; end
def irregular(singular, plural); end
def plural(rule, replacement); end
def plurals; end
def singular(rule, replacement); end
def singulars; end
def uncountable(*words); end
def uncountables; end
private
def define_acronym_regex_patterns; end
def initialize_dup(orig); end
class << self
def instance(locale = T.unsafe(nil)); end
end
end
class ActiveSupport::Inflector::Inflections::Uncountables < ::Array
def initialize; end
def <<(*word); end
def add(words); end
def delete(entry); end
def uncountable?(str); end
private
def to_regex(string); end
end
module ActiveSupport::LazyLoadHooks
def on_load(name, options = T.unsafe(nil), &block); end
def run_load_hooks(name, base = T.unsafe(nil)); end
private
def execute_hook(name, base, options, block); end
def with_execution_control(name, block, once); end
class << self
def extended(base); end
end
end
module ActiveSupport::Multibyte
class << self
def proxy_class; end
def proxy_class=(klass); end
end
end
class ActiveSupport::Multibyte::Chars
include(::Comparable)
def initialize(string); end
def <=>(*args, &block); end
def =~(*args, &block); end
def acts_like_string?(*args, &block); end
def as_json(options = T.unsafe(nil)); end
def compose; end
def decompose; end
def grapheme_length; end
def limit(limit); end
def match?(*args, &block); end
def method_missing(method, *args, &block); end
def reverse; end
def reverse!(*args); end
def slice!(*args); end
def split(*args); end
def tidy_bytes(force = T.unsafe(nil)); end
def tidy_bytes!(*args); end
def titlecase; end
def titleize; end
def to_s; end
def to_str; end
def wrapped_string; end
private
def chars(string); end
def respond_to_missing?(method, include_private); end
end
module ActiveSupport::Multibyte::Unicode
extend(::ActiveSupport::Multibyte::Unicode)
def compose(codepoints); end
def decompose(type, codepoints); end
def default_normalization_form; end
def default_normalization_form=(_); end
def tidy_bytes(string, force = T.unsafe(nil)); end
private
def recode_windows1252_chars(string); end
end
ActiveSupport::Multibyte::Unicode::UNICODE_VERSION = T.let(T.unsafe(nil), String)
module ActiveSupport::BigDecimalWithDefaultFormat
def to_s(format = T.unsafe(nil)); end
end
module ActiveSupport::JSON
class << self
def decode(json); end
def encode(value, options = T.unsafe(nil)); end
def parse_error; end
private
def convert_dates_from(data); end
end
end
ActiveSupport::JSON::DATETIME_REGEX = T.let(T.unsafe(nil), Regexp)
ActiveSupport::JSON::DATE_REGEX = T.let(T.unsafe(nil), Regexp)
module ActiveSupport::JSON::Encoding
class << self
def escape_html_entities_in_json; end
def escape_html_entities_in_json=(_arg0); end
def json_encoder; end
def json_encoder=(_arg0); end
def time_precision; end
def time_precision=(_arg0); end
def use_standard_json_time_format; end
def use_standard_json_time_format=(_arg0); end
end
end
class ActiveSupport::JSON::Encoding::JSONGemEncoder
def initialize(options = T.unsafe(nil)); end
def encode(value); end
def options; end
private
def jsonify(value); end
def stringify(jsonified); end
end
class ActiveSupport::TimeZone
include(::Comparable)
def initialize(name, utc_offset = T.unsafe(nil), tzinfo = T.unsafe(nil)); end
def <=>(zone); end
def =~(re); end
def at(*args); end
def encode_with(coder); end
def formatted_offset(colon = T.unsafe(nil), alternate_utc_string = T.unsafe(nil)); end
def init_with(coder); end
def iso8601(str); end
def local(*args); end
def local_to_utc(time, dst = T.unsafe(nil)); end
def match?(re); end
def name; end
def now; end
def parse(str, now = T.unsafe(nil)); end
def period_for_local(time, dst = T.unsafe(nil)); end
def period_for_utc(time); end
def periods_for_local(time); end
def rfc3339(str); end
def strptime(str, format, now = T.unsafe(nil)); end
def to_s; end
def today; end
def tomorrow; end
def tzinfo; end
def utc_offset; end
def utc_to_local(time); end
def yesterday; end
private
def parts_to_time(parts, now); end
def time_now; end
class << self
def [](arg); end
def all; end
def clear; end
def country_zones(country_code); end
def create(*_arg0); end
def find_tzinfo(name); end
def new(name); end
def seconds_to_utc_offset(seconds, colon = T.unsafe(nil)); end
def us_zones; end
private
def load_country_zones(code); end
def zones_map; end
end
end
ActiveSupport::TimeZone::MAPPING = T.let(T.unsafe(nil), Hash)
module ActiveSupport::ToJsonWithActiveSupportEncoder
def to_json(options = T.unsafe(nil)); end
end
class Array
include(::Enumerable)
include(::JSON::Ext::Generator::GeneratorMethods::Array)
include(::Plist::Emit)
def as_json(options = T.unsafe(nil)); end
end
class BigDecimal < ::Numeric
include(::ActiveSupport::BigDecimalWithDefaultFormat)
def as_json(options = T.unsafe(nil)); end
end
BigDecimal::EXCEPTION_NaN = T.let(T.unsafe(nil), Integer)
BigDecimal::VERSION = T.let(T.unsafe(nil), String)
class Date
include(::Comparable)
include(::DateAndTime::Zones)
def as_json(options = T.unsafe(nil)); end
def inspect; end
def readable_inspect; end
def to_formatted_s(format = T.unsafe(nil)); end
def to_s(format = T.unsafe(nil)); end
def to_time(form = T.unsafe(nil)); end
def xmlschema; end
end
Date::DATE_FORMATS = T.let(T.unsafe(nil), Hash)
module DateAndTime
end
module DateAndTime::Zones
def in_time_zone(zone = T.unsafe(nil)); end
private
def time_with_zone(time, zone); end
end
class DateTime < ::Date
def <=>(other); end
def advance(options); end
def ago(seconds); end
def as_json(options = T.unsafe(nil)); end
def at_beginning_of_day; end
def at_beginning_of_hour; end
def at_beginning_of_minute; end
def at_end_of_day; end
def at_end_of_hour; end
def at_end_of_minute; end
def at_midday; end
def at_middle_of_day; end
def at_midnight; end
def at_noon; end
def beginning_of_day; end
def beginning_of_hour; end
def beginning_of_minute; end
def change(options); end
def end_of_day; end
def end_of_hour; end
def end_of_minute; end
def formatted_offset(colon = T.unsafe(nil), alternate_utc_string = T.unsafe(nil)); end
def getgm; end
def getlocal(utc_offset = T.unsafe(nil)); end
def getutc; end
def gmtime; end
def in(seconds); end
def inspect; end
def localtime(utc_offset = T.unsafe(nil)); end
def midday; end
def middle_of_day; end
def midnight; end
def noon; end
def nsec; end
def readable_inspect; end
def seconds_since_midnight; end
def seconds_until_end_of_day; end
def since(seconds); end
def subsec; end
def to_f; end
def to_formatted_s(format = T.unsafe(nil)); end
def to_i; end
def to_s(format = T.unsafe(nil)); end
def usec; end
def utc; end
def utc?; end
def utc_offset; end
private
def offset_in_seconds; end
def seconds_since_unix_epoch; end
class << self
def civil_from_format(utc_or_local, year, month = T.unsafe(nil), day = T.unsafe(nil), hour = T.unsafe(nil), min = T.unsafe(nil), sec = T.unsafe(nil)); end
def current; end
end
end
module Enumerable
def as_json(options = T.unsafe(nil)); end
end
class Exception
def as_json(options = T.unsafe(nil)); end
end
class FalseClass
include(::JSON::Ext::Generator::GeneratorMethods::FalseClass)
def as_json(options = T.unsafe(nil)); end
def blank?; end
end
class Float < ::Numeric
include(::JSON::Ext::Generator::GeneratorMethods::Float)
def as_json(options = T.unsafe(nil)); end
end
class Hash
include(::Enumerable)
include(::JSON::Ext::Generator::GeneratorMethods::Hash)
include(::Plist::Emit)
def as_json(options = T.unsafe(nil)); end
def deep_merge(other_hash, &block); end
def deep_merge!(other_hash, &block); end
def except(*keys); end
def except!(*keys); end
def extract!(*keys); end
def slice!(*keys); end
end
class IO
include(::Enumerable)
include(::File::Constants)
def as_json(options = T.unsafe(nil)); end
end
IO::EWOULDBLOCKWaitReadable = IO::EAGAINWaitReadable
IO::EWOULDBLOCKWaitWritable = IO::EAGAINWaitWritable
class Module
def cattr_accessor(*syms, instance_reader: T.unsafe(nil), instance_writer: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), &blk); end
def cattr_reader(*syms, instance_reader: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), location: T.unsafe(nil)); end
def cattr_writer(*syms, instance_writer: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), location: T.unsafe(nil)); end
def delegate(*methods, to: T.unsafe(nil), prefix: T.unsafe(nil), allow_nil: T.unsafe(nil), private: T.unsafe(nil)); end
def delegate_missing_to(target, allow_nil: T.unsafe(nil)); end
def mattr_accessor(*syms, instance_reader: T.unsafe(nil), instance_writer: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), &blk); end
def mattr_reader(*syms, instance_reader: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), location: T.unsafe(nil)); end
def mattr_writer(*syms, instance_writer: T.unsafe(nil), instance_accessor: T.unsafe(nil), default: T.unsafe(nil), location: T.unsafe(nil)); end
def method_visibility(method); end
def redefine_method(method, &block); end
def redefine_singleton_method(method, &block); end
def silence_redefinition_of_method(method); end
end
Module::DELEGATION_RESERVED_KEYWORDS = T.let(T.unsafe(nil), Array)
Module::DELEGATION_RESERVED_METHOD_NAMES = T.let(T.unsafe(nil), Set)
class Module::DelegationError < ::NoMethodError
end
Module::RUBY_RESERVED_KEYWORDS = T.let(T.unsafe(nil), Array)
class NilClass
include(::JSON::Ext::Generator::GeneratorMethods::NilClass)
def as_json(options = T.unsafe(nil)); end
def blank?; end
end
class Numeric
include(::Comparable)
def as_json(options = T.unsafe(nil)); end
def blank?; end
end
class Object < ::BasicObject
include(::ActiveSupport::ToJsonWithActiveSupportEncoder)
include(::Kernel)
include(::JSON::Ext::Generator::GeneratorMethods::Object)
include(::PP::ObjectMixin)
def as_json(options = T.unsafe(nil)); end
def blank?; end
def instance_values; end
def instance_variable_names; end
def presence; end
def present?; end
end
::APPLE_GEM_HOME = T.let(T.unsafe(nil), String)
::RUBY_FRAMEWORK = T.let(T.unsafe(nil), TrueClass)
::RUBY_FRAMEWORK_VERSION = T.let(T.unsafe(nil), String)
class Pathname
def as_json(options = T.unsafe(nil)); end
end
class Process::Status
def as_json(options = T.unsafe(nil)); end
end
class Range
include(::Enumerable)
def as_json(options = T.unsafe(nil)); end
end
class Regexp
def as_json(options = T.unsafe(nil)); end
end
Regexp::TOKEN_KEYS = T.let(T.unsafe(nil), Array)
class Regexp::Token < ::Struct
def conditional_level; end
def conditional_level=(_); end
def length; end
def level; end
def level=(_); end
def next; end
def next=(_arg0); end
def offset; end
def previous; end
def previous=(_arg0); end
def set_level; end
def set_level=(_); end
def te; end
def te=(_); end
def text; end
def text=(_); end
def token; end
def token=(_); end
def ts; end
def ts=(_); end
def type; end
def type=(_); end
class << self
def [](*_arg0); end
def inspect; end
def members; end
def new(*_arg0); end
end
end
class String
include(::Comparable)
include(::JSON::Ext::Generator::GeneratorMethods::String)
include(::Colorize::InstanceMethods)
extend(::JSON::Ext::Generator::GeneratorMethods::String::Extend)
extend(::Colorize::ClassMethods)
def acts_like_string?; end
def as_json(options = T.unsafe(nil)); end
def at(position); end
def blank?; end
def camelcase(first_letter = T.unsafe(nil)); end
def camelize(first_letter = T.unsafe(nil)); end
def classify; end
def constantize; end
def dasherize; end
def deconstantize; end
def demodulize; end
def first(limit = T.unsafe(nil)); end
def foreign_key(separate_class_name_and_id_with_underscore = T.unsafe(nil)); end
def from(position); end
def humanize(capitalize: T.unsafe(nil), keep_id_suffix: T.unsafe(nil)); end
def is_utf8?; end
def last(limit = T.unsafe(nil)); end
def mb_chars; end
def parameterize(separator: T.unsafe(nil), preserve_case: T.unsafe(nil), locale: T.unsafe(nil)); end
def pluralize(count = T.unsafe(nil), locale = T.unsafe(nil)); end
def safe_constantize; end
def singularize(locale = T.unsafe(nil)); end
def tableize; end
def titlecase(keep_id_suffix: T.unsafe(nil)); end
def titleize(keep_id_suffix: T.unsafe(nil)); end
def to(position); end
def underscore; end
def upcase_first; end
end
String::BLANK_RE = T.let(T.unsafe(nil), Regexp)
String::ENCODED_BLANKS = T.let(T.unsafe(nil), Concurrent::Map)
class Struct
include(::Enumerable)
def as_json(options = T.unsafe(nil)); end
end
Struct::Group = Etc::Group
Struct::HTMLElementDescription = Struct
Struct::Passwd = Etc::Passwd
Struct::Tms = Process::Tms
class Symbol
include(::Comparable)
def as_json(options = T.unsafe(nil)); end
def end_with?(*suffixes); end
def ends_with?(*suffixes); end
def start_with?(*prefixes); end
def starts_with?(*prefixes); end
end
class Time
include(::Comparable)
def as_json(options = T.unsafe(nil)); end
def blank?; end
def formatted_offset(colon = T.unsafe(nil), alternate_utc_string = T.unsafe(nil)); end
def to_formatted_s(format = T.unsafe(nil)); end
def to_s(format = T.unsafe(nil)); end
end
Time::DATE_FORMATS = T.let(T.unsafe(nil), Hash)
class TrueClass
include(::JSON::Ext::Generator::GeneratorMethods::TrueClass)
def as_json(options = T.unsafe(nil)); end
def blank?; end
end
class URI::Generic
include(::URI::RFC2396_REGEXP)
include(::URI)
def as_json(options = T.unsafe(nil)); end
end

View File

@ -1,7 +0,0 @@
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `thread_safe` gem.
# Please instead update this file by running `tapioca generate --exclude json`.
# typed: true

View File

@ -1,8 +0,0 @@
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `tzinfo` gem.
# Please instead update this file by running `tapioca sync`.
# typed: true
# THIS IS AN EMPTY RBI FILE.
# see https://github.com/Shopify/tapioca/blob/master/README.md#manual-gem-requires

View File

@ -0,0 +1,566 @@
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `tzinfo` gem.
# Please instead update this file by running `tapioca sync`.
# typed: true
module TZInfo
end
class TZInfo::AbsoluteDayOfYearTransitionRule
def initialize(day, transition_at = T.unsafe(nil)); end
def ==(r); end
def eql?(r); end
def is_always_first_day_of_year?; end
def is_always_last_day_of_year?; end
protected
def get_day(offset, year); end
def hash_args; end
end
class TZInfo::AmbiguousTime < ::StandardError
end
class TZInfo::Country
include(::Comparable)
def initialize(info); end
def <=>(c); end
def =~(regexp); end
def _dump(limit); end
def code; end
def eql?(c); end
def hash; end
def inspect; end
def name; end
def to_s; end
def zone_identifiers; end
def zone_info; end
def zone_names; end
def zones; end
class << self
def _load(data); end
def all; end
def all_codes; end
def get(code); end
private
def data_source; end
end
end
class TZInfo::CountryTimezone
def initialize(identifier, latitude, longitude, description = T.unsafe(nil)); end
def ==(ct); end
def description; end
def description_or_friendly_identifier; end
def eql?(ct); end
def hash; end
def identifier; end
def latitude; end
def longitude; end
def timezone; end
end
class TZInfo::DataSource
def initialize; end
def country_codes; end
def data_timezone_identifiers; end
def get_country_info(code); end
def get_timezone_info(identifier); end
def inspect; end
def linked_timezone_identifiers; end
def timezone_identifiers; end
def to_s; end
protected
def load_country_info(code); end
def load_timezone_info(identifier); end
def lookup_country_info(hash, code, encoding = T.unsafe(nil)); end
def timezone_identifier_encoding; end
def validate_timezone_identifier(identifier); end
private
def build_timezone_identifiers; end
def find_timezone_identifier(identifier); end
def raise_invalid_data_source(method_name); end
def try_with_encoding(string, encoding); end
class << self
def get; end
def set(data_source_or_type, *args); end
private
def create_default_data_source; end
end
end
class TZInfo::DataSourceNotFound < ::StandardError
end
module TZInfo::DataSources
end
class TZInfo::DataSources::ConstantOffsetDataTimezoneInfo < ::TZInfo::DataSources::DataTimezoneInfo
def initialize(identifier, constant_offset); end
def constant_offset; end
def period_for(timestamp); end
def periods_for_local(local_timestamp); end
def transitions_up_to(to_timestamp, from_timestamp = T.unsafe(nil)); end
private
def constant_period; end
end
class TZInfo::DataSources::CountryInfo
def initialize(code, name, zones); end
def code; end
def inspect; end
def name; end
def zones; end
end
class TZInfo::DataSources::DataTimezoneInfo < ::TZInfo::DataSources::TimezoneInfo
def create_timezone; end
def period_for(timestamp); end
def periods_for_local(local_timestamp); end
def transitions_up_to(to_timestamp, from_timestamp = T.unsafe(nil)); end
private
def raise_not_implemented(method_name); end
end
class TZInfo::DataSources::InvalidZoneinfoDirectory < ::StandardError
end
class TZInfo::DataSources::InvalidZoneinfoFile < ::StandardError
end
class TZInfo::DataSources::LinkedTimezoneInfo < ::TZInfo::DataSources::TimezoneInfo
def initialize(identifier, link_to_identifier); end
def create_timezone; end
def link_to_identifier; end
end
class TZInfo::DataSources::RubyDataSource < ::TZInfo::DataSource
def initialize; end
def country_codes; end
def data_timezone_identifiers; end
def inspect; end
def linked_timezone_identifiers; end
def to_s; end
protected
def load_country_info(code); end
def load_timezone_info(identifier); end
private
def require_data(*file); end
def require_definition(identifier); end
def require_index(name); end
def version_info; end
end
class TZInfo::DataSources::TZInfoDataNotFound < ::StandardError
end
class TZInfo::DataSources::TimezoneInfo
def initialize(identifier); end
def create_timezone; end
def identifier; end
def inspect; end
private
def raise_not_implemented(method_name); end
end
class TZInfo::DataSources::TransitionsDataTimezoneInfo < ::TZInfo::DataSources::DataTimezoneInfo
def initialize(identifier, transitions); end
def period_for(timestamp); end
def periods_for_local(local_timestamp); end
def transitions; end
def transitions_up_to(to_timestamp, from_timestamp = T.unsafe(nil)); end
private
def find_minimum_transition(&block); end
def transition_on_or_after_timestamp?(transition, timestamp); end
end
class TZInfo::DataSources::ZoneinfoDataSource < ::TZInfo::DataSource
def initialize(zoneinfo_dir = T.unsafe(nil), alternate_iso3166_tab_path = T.unsafe(nil)); end
def country_codes; end
def data_timezone_identifiers; end
def inspect; end
def linked_timezone_identifiers; end
def to_s; end
def zoneinfo_dir; end
protected
def load_country_info(code); end
def load_timezone_info(identifier); end
private
def dms_to_rational(sign, degrees, minutes, seconds = T.unsafe(nil)); end
def enum_timezones(dir, exclude = T.unsafe(nil), &block); end
def find_zoneinfo_dir; end
def load_countries(iso3166_tab_path, zone_tab_path); end
def load_timezone_identifiers; end
def resolve_tab_path(zoneinfo_path, standard_names, tab_name); end
def validate_zoneinfo_dir(path, iso3166_tab_path = T.unsafe(nil)); end
class << self
def alternate_iso3166_tab_search_path; end
def alternate_iso3166_tab_search_path=(alternate_iso3166_tab_search_path); end
def search_path; end
def search_path=(search_path); end
private
def process_search_path(path, default); end
end
end
class TZInfo::DataSources::ZoneinfoDirectoryNotFound < ::StandardError
end
class TZInfo::DataTimezone < ::TZInfo::InfoTimezone
def canonical_zone; end
def period_for(time); end
def periods_for_local(local_time); end
def transitions_up_to(to, from = T.unsafe(nil)); end
end
class TZInfo::DateTimeWithOffset < ::DateTime
include(::TZInfo::WithOffset)
def downto(min); end
def england; end
def gregorian; end
def italy; end
def julian; end
def new_start(start = T.unsafe(nil)); end
def set_timezone_offset(timezone_offset); end
def step(limit, step = T.unsafe(nil)); end
def timezone_offset; end
def to_time; end
def upto(max); end
protected
def clear_timezone_offset; end
end
class TZInfo::InfoTimezone < ::TZInfo::Timezone
def initialize(info); end
def identifier; end
protected
def info; end
end
class TZInfo::InvalidCountryCode < ::StandardError
end
class TZInfo::InvalidDataSource < ::StandardError
end
class TZInfo::InvalidTimezoneIdentifier < ::StandardError
end
class TZInfo::LinkedTimezone < ::TZInfo::InfoTimezone
def initialize(info); end
def canonical_zone; end
def period_for(time); end
def periods_for_local(local_time); end
def transitions_up_to(to, from = T.unsafe(nil)); end
end
class TZInfo::OffsetTimezonePeriod < ::TZInfo::TimezonePeriod
def initialize(offset); end
def ==(p); end
def end_transition; end
def eql?(p); end
def hash; end
def start_transition; end
end
class TZInfo::PeriodNotFound < ::StandardError
end
class TZInfo::TimeWithOffset < ::Time
include(::TZInfo::WithOffset)
def dst?; end
def getlocal(*args); end
def gmtime; end
def isdst; end
def localtime(*args); end
def round(ndigits = T.unsafe(nil)); end
def set_timezone_offset(timezone_offset); end
def timezone_offset; end
def to_a; end
def to_datetime; end
def utc; end
def zone; end
protected
def clear_timezone_offset; end
end
class TZInfo::Timestamp
include(::Comparable)
def initialize(value, sub_second = T.unsafe(nil), utc_offset = T.unsafe(nil)); end
def <=>(t); end
def add_and_set_utc_offset(seconds, utc_offset); end
def eql?(_arg0); end
def hash; end
def inspect; end
def strftime(format); end
def sub_second; end
def to_datetime; end
def to_i; end
def to_s; end
def to_time; end
def utc; end
def utc?; end
def utc_offset; end
def value; end
protected
def new_datetime(klass = T.unsafe(nil)); end
def new_time(klass = T.unsafe(nil)); end
private
def initialize!(value, sub_second = T.unsafe(nil), utc_offset = T.unsafe(nil)); end
def sub_second_to_s; end
def value_and_sub_second_to_s(offset = T.unsafe(nil)); end
class << self
def create(year, month = T.unsafe(nil), day = T.unsafe(nil), hour = T.unsafe(nil), minute = T.unsafe(nil), second = T.unsafe(nil), sub_second = T.unsafe(nil), utc_offset = T.unsafe(nil)); end
def for(value, offset = T.unsafe(nil)); end
def utc(value, sub_second = T.unsafe(nil)); end
private
def for_datetime(datetime, ignore_offset, target_utc_offset); end
def for_time(time, ignore_offset, target_utc_offset); end
def for_time_like(time_like, ignore_offset, target_utc_offset); end
def for_timestamp(timestamp, ignore_offset, target_utc_offset); end
def is_time_like?(value); end
def new!(value, sub_second = T.unsafe(nil), utc_offset = T.unsafe(nil)); end
end
end
class TZInfo::TimestampWithOffset < ::TZInfo::Timestamp
include(::TZInfo::WithOffset)
def set_timezone_offset(timezone_offset); end
def timezone_offset; end
def to_datetime; end
def to_time; end
class << self
def set_timezone_offset(timestamp, timezone_offset); end
end
end
class TZInfo::Timezone
include(::Comparable)
def <=>(tz); end
def =~(regexp); end
def _dump(limit); end
def abbr(time = T.unsafe(nil)); end
def abbreviation(time = T.unsafe(nil)); end
def base_utc_offset(time = T.unsafe(nil)); end
def canonical_identifier; end
def canonical_zone; end
def current_period; end
def current_period_and_time; end
def current_time_and_period; end
def dst?(time = T.unsafe(nil)); end
def eql?(tz); end
def friendly_identifier(skip_first_part = T.unsafe(nil)); end
def hash; end
def identifier; end
def inspect; end
def local_datetime(year, month = T.unsafe(nil), day = T.unsafe(nil), hour = T.unsafe(nil), minute = T.unsafe(nil), second = T.unsafe(nil), sub_second = T.unsafe(nil), dst = T.unsafe(nil), &block); end
def local_time(year, month = T.unsafe(nil), day = T.unsafe(nil), hour = T.unsafe(nil), minute = T.unsafe(nil), second = T.unsafe(nil), sub_second = T.unsafe(nil), dst = T.unsafe(nil), &block); end
def local_timestamp(year, month = T.unsafe(nil), day = T.unsafe(nil), hour = T.unsafe(nil), minute = T.unsafe(nil), second = T.unsafe(nil), sub_second = T.unsafe(nil), dst = T.unsafe(nil), &block); end
def local_to_utc(local_time, dst = T.unsafe(nil)); end
def name; end
def now; end
def observed_utc_offset(time = T.unsafe(nil)); end
def offsets_up_to(to, from = T.unsafe(nil)); end
def period_for(time); end
def period_for_local(local_time, dst = T.unsafe(nil)); end
def period_for_utc(utc_time); end
def periods_for_local(local_time); end
def strftime(format, time = T.unsafe(nil)); end
def to_local(time); end
def to_s; end
def transitions_up_to(to, from = T.unsafe(nil)); end
def utc_offset(time = T.unsafe(nil)); end
def utc_to_local(utc_time); end
private
def raise_unknown_timezone; end
class << self
def _load(data); end
def all; end
def all_country_zone_identifiers; end
def all_country_zones; end
def all_data_zone_identifiers; end
def all_data_zones; end
def all_identifiers; end
def all_linked_zone_identifiers; end
def all_linked_zones; end
def default_dst; end
def default_dst=(value); end
def get(identifier); end
def get_proxy(identifier); end
private
def data_source; end
def get_proxies(identifiers); end
end
end
class TZInfo::TimezoneOffset
def initialize(base_utc_offset, std_offset, abbreviation); end
def ==(toi); end
def abbr; end
def abbreviation; end
def base_utc_offset; end
def dst?; end
def eql?(toi); end
def hash; end
def inspect; end
def observed_utc_offset; end
def std_offset; end
def utc_offset; end
def utc_total_offset; end
end
class TZInfo::TimezonePeriod
def initialize(offset); end
def abbr; end
def abbreviation; end
def base_utc_offset; end
def dst?; end
def end_transition; end
def ends_at; end
def local_ends_at; end
def local_starts_at; end
def observed_utc_offset; end
def offset; end
def start_transition; end
def starts_at; end
def std_offset; end
def utc_offset; end
def utc_total_offset; end
def zone_identifier; end
private
def raise_not_implemented(method_name); end
def timestamp(transition); end
def timestamp_with_offset(transition); end
end
class TZInfo::TimezoneProxy < ::TZInfo::Timezone
def initialize(identifier); end
def _dump(limit); end
def canonical_zone; end
def identifier; end
def period_for(time); end
def periods_for_local(local_time); end
def transitions_up_to(to, from = T.unsafe(nil)); end
private
def real_timezone; end
class << self
def _load(data); end
end
end
class TZInfo::TimezoneTransition
def initialize(offset, previous_offset, timestamp_value); end
def ==(tti); end
def at; end
def eql?(tti); end
def hash; end
def local_end_at; end
def local_start_at; end
def offset; end
def previous_offset; end
def timestamp_value; end
end
class TZInfo::TransitionsTimezonePeriod < ::TZInfo::TimezonePeriod
def initialize(start_transition, end_transition); end
def ==(p); end
def end_transition; end
def eql?(p); end
def hash; end
def inspect; end
def start_transition; end
end
class TZInfo::UnknownTimezone < ::StandardError
end
TZInfo::VERSION = T.let(T.unsafe(nil), String)
module TZInfo::WithOffset
def strftime(format); end
protected
def if_timezone_offset(result = T.unsafe(nil)); end
end

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,9 @@ path = File.expand_path('..', __FILE__)
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.8.5/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.8.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.14.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.14.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thread_safe-0.3.6/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-2.0.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-1.2.8/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.4.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.4.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.0.3.4/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.1.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bindata-2.4.8/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bindata-2.4.8/lib"
$:.unshift "#{path}/" $:.unshift "#{path}/"

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
require "active_support/deprecation"
ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Array#append and Array#prepend natively, so requiring active_support/core_ext/array/prepend_and_append is no longer necessary. Requiring it will raise LoadError in Rails 6.1."

View File

@ -1,54 +0,0 @@
# frozen_string_literal: true
class Class
begin
# Test if this Ruby supports each_object against singleton_class
ObjectSpace.each_object(Numeric.singleton_class) { }
# Returns an array with all classes that are < than its receiver.
#
# class C; end
# C.descendants # => []
#
# class B < C; end
# C.descendants # => [B]
#
# class A < B; end
# C.descendants # => [B, A]
#
# class D < C; end
# C.descendants # => [B, A, D]
def descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
next if k.singleton_class?
descendants.unshift k unless k == self
end
descendants
end
rescue StandardError # JRuby 9.0.4.0 and earlier
def descendants
descendants = []
ObjectSpace.each_object(Class) do |k|
descendants.unshift k if k < self
end
descendants.uniq!
descendants
end
end
# Returns an array with the direct children of +self+.
#
# class Foo; end
# class Bar < Foo; end
# class Baz < Bar; end
#
# Foo.subclasses # => [Bar]
def subclasses
subclasses, chain = [], descendants
chain.each do |k|
subclasses << k unless chain.any? { |c| c > k }
end
subclasses
end
end

View File

@ -1,16 +0,0 @@
# frozen_string_literal: true
require "active_support/core_ext/module/attribute_accessors"
module DateAndTime
module Compatibility
# If true, +to_time+ preserves the timezone offset of receiver.
#
# NOTE: With Ruby 2.4+ the default for +to_time+ changed from
# converting to the local system time, to preserving the offset
# of the receiver. For backwards compatibility we're overriding
# this behavior, but new apps will have an initializer that sets
# this to true, because the new behavior is preferred.
mattr_accessor :preserve_timezone, instance_writer: false, default: false
end
end

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
require "active_support/deprecation"
ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Hash#compact and Hash#compact! natively, so requiring active_support/core_ext/hash/compact is no longer necessary. Requiring it will raise LoadError in Rails 6.1."

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
require "active_support/deprecation"
ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Hash#transform_values natively, so requiring active_support/core_ext/hash/transform_values is no longer necessary. Requiring it will raise LoadError in Rails 6.1."

View File

@ -1,6 +0,0 @@
# frozen_string_literal: true
require "active_support/core_ext/module/anonymous"
require "active_support/core_ext/string/inflections"
ActiveSupport::Deprecation.warn("reachable is deprecated and will be removed from the framework.")

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
require "active_support/deprecation"
ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Numeric#positive? and Numeric#negative? natively, so requiring active_support/core_ext/numeric/inquiry is no longer necessary. Requiring it will raise LoadError in Rails 6.1."

View File

@ -1,9 +0,0 @@
# frozen_string_literal: true
require "active_support/deprecation"
ActiveSupport::Deprecation.warn "You have required `active_support/core_ext/range/include_range`. " \
"This file will be removed in Rails 6.1. You should require `active_support/core_ext/range/compare_range` " \
"instead."
require "active_support/core_ext/range/compare_range"

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
class Regexp #:nodoc:
def multiline?
options & MULTILINE == MULTILINE
end
end

View File

@ -1,6 +0,0 @@
# frozen_string_literal: true
class String
alias_method :starts_with?, :start_with?
alias_method :ends_with?, :end_with?
end

View File

@ -1,234 +0,0 @@
# frozen_string_literal: true
require "set"
require "pathname"
require "concurrent/atomic/atomic_boolean"
module ActiveSupport
# Allows you to "listen" to changes in a file system.
# The evented file updater does not hit disk when checking for updates
# instead it uses platform specific file system events to trigger a change
# in state.
#
# The file checker takes an array of files to watch or a hash specifying directories
# and file extensions to watch. It also takes a block that is called when
# EventedFileUpdateChecker#execute is run or when EventedFileUpdateChecker#execute_if_updated
# is run and there have been changes to the file system.
#
# Note: Forking will cause the first call to `updated?` to return `true`.
#
# Example:
#
# checker = ActiveSupport::EventedFileUpdateChecker.new(["/tmp/foo"]) { puts "changed" }
# checker.updated?
# # => false
# checker.execute_if_updated
# # => nil
#
# FileUtils.touch("/tmp/foo")
#
# checker.updated?
# # => true
# checker.execute_if_updated
# # => "changed"
#
class EventedFileUpdateChecker #:nodoc: all
def initialize(files, dirs = {}, &block)
unless block
raise ArgumentError, "A block is required to initialize an EventedFileUpdateChecker"
end
@ph = PathHelper.new
@files = files.map { |f| @ph.xpath(f) }.to_set
@dirs = {}
dirs.each do |dir, exts|
@dirs[@ph.xpath(dir)] = Array(exts).map { |ext| @ph.normalize_extension(ext) }
end
@block = block
@updated = Concurrent::AtomicBoolean.new(false)
@lcsp = @ph.longest_common_subpath(@dirs.keys)
@pid = Process.pid
@boot_mutex = Mutex.new
dtw = directories_to_watch
@dtw, @missing = dtw.partition(&:exist?)
if @dtw.any?
# Loading listen triggers warnings. These are originated by a legit
# usage of attr_* macros for private attributes, but adds a lot of noise
# to our test suite. Thus, we lazy load it and disable warnings locally.
silence_warnings do
require "listen"
rescue LoadError => e
raise LoadError, "Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile", e.backtrace
end
end
boot!
end
def updated?
@boot_mutex.synchronize do
if @pid != Process.pid
boot!
@pid = Process.pid
@updated.make_true
end
end
if @missing.any?(&:exist?)
@boot_mutex.synchronize do
appeared, @missing = @missing.partition(&:exist?)
shutdown!
@dtw += appeared
boot!
@updated.make_true
end
end
@updated.true?
end
def execute
@updated.make_false
@block.call
end
def execute_if_updated
if updated?
yield if block_given?
execute
true
end
end
private
def boot!
normalize_dirs!
unless @dtw.empty?
Listen.to(*@dtw, &method(:changed)).start
end
end
def shutdown!
Listen.stop
end
def normalize_dirs!
@dirs.transform_keys! do |dir|
dir.exist? ? dir.realpath : dir
end
end
def changed(modified, added, removed)
unless updated?
@updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
end
end
def watching?(file)
file = @ph.xpath(file)
if @files.member?(file)
true
elsif file.directory?
false
else
ext = @ph.normalize_extension(file.extname)
file.dirname.ascend do |dir|
matching = @dirs[dir]
if matching && (matching.empty? || matching.include?(ext))
break true
elsif dir == @lcsp || dir.root?
break false
end
end
end
end
def directories_to_watch
dtw = @files.map(&:dirname) + @dirs.keys
dtw.compact!
dtw.uniq!
normalized_gem_paths = Gem.path.map { |path| File.join path, "" }
dtw = dtw.reject do |path|
normalized_gem_paths.any? { |gem_path| path.to_s.start_with?(gem_path) }
end
@ph.filter_out_descendants(dtw)
end
class PathHelper
def xpath(path)
Pathname.new(path).expand_path
end
def normalize_extension(ext)
ext.to_s.sub(/\A\./, "")
end
# Given a collection of Pathname objects returns the longest subpath
# common to all of them, or +nil+ if there is none.
def longest_common_subpath(paths)
return if paths.empty?
lcsp = Pathname.new(paths[0])
paths[1..-1].each do |path|
until ascendant_of?(lcsp, path)
if lcsp.root?
# If we get here a root directory is not an ascendant of path.
# This may happen if there are paths in different drives on
# Windows.
return
else
lcsp = lcsp.parent
end
end
end
lcsp
end
# Returns the deepest existing ascendant, which could be the argument itself.
def existing_parent(dir)
dir.ascend do |ascendant|
break ascendant if ascendant.directory?
end
end
# Filters out directories which are descendants of others in the collection (stable).
def filter_out_descendants(dirs)
return dirs if dirs.length < 2
dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length }
descendants = []
until dirs_sorted_by_nparts.empty?
dir = dirs_sorted_by_nparts.shift
dirs_sorted_by_nparts.reject! do |possible_descendant|
ascendant_of?(dir, possible_descendant) && descendants << possible_descendant
end
end
# Array#- preserves order.
dirs - descendants
end
private
def ascendant_of?(base, other)
base != other && other.ascend do |ascendant|
break true if base == ascendant
end
end
end
end
end

View File

@ -1,45 +0,0 @@
# frozen_string_literal: true
require "active_support/concern"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/logger_thread_safe_level"
module LoggerSilence
extend ActiveSupport::Concern
included do
ActiveSupport::Deprecation.warn(
"Including LoggerSilence is deprecated and will be removed in Rails 6.1. " \
"Please use `ActiveSupport::LoggerSilence` instead"
)
include ActiveSupport::LoggerSilence
end
end
module ActiveSupport
module LoggerSilence
extend ActiveSupport::Concern
included do
cattr_accessor :silencer, default: true
include ActiveSupport::LoggerThreadSafeLevel
end
# Silences the logger for the duration of the block.
def silence(temporary_level = Logger::ERROR)
if silencer
begin
old_local_level = local_level
self.local_level = temporary_level
yield self
ensure
self.local_level = old_local_level
end
else
yield self
end
end
end
end

View File

@ -1,56 +0,0 @@
# frozen_string_literal: true
require "active_support/concern"
require "active_support/core_ext/module/attribute_accessors"
require "concurrent"
require "fiber"
module ActiveSupport
module LoggerThreadSafeLevel # :nodoc:
extend ActiveSupport::Concern
included do
cattr_accessor :local_levels, default: Concurrent::Map.new(initial_capacity: 2), instance_accessor: false
end
Logger::Severity.constants.each do |severity|
class_eval(<<-EOT, __FILE__, __LINE__ + 1)
def #{severity.downcase}? # def debug?
Logger::#{severity} >= level # DEBUG >= level
end # end
EOT
end
def after_initialize
ActiveSupport::Deprecation.warn(
"Logger don't need to call #after_initialize directly anymore. It will be deprecated without replacement in " \
"Rails 6.1."
)
end
def local_log_id
Fiber.current.__id__
end
def local_level
self.class.local_levels[local_log_id]
end
def local_level=(level)
if level
self.class.local_levels[local_log_id] = level
else
self.class.local_levels.delete(local_log_id)
end
end
def level
local_level || super
end
def add(severity, message = nil, progname = nil, &block) # :nodoc:
return true if @logdev.nil? || (severity || UNKNOWN) < level
super
end
end
end

View File

@ -1,31 +0,0 @@
# frozen_string_literal: true
require "digest/sha2"
module ActiveSupport
module SecurityUtils
# Constant time string comparison, for fixed length strings.
#
# The values compared should be of fixed length, such as strings
# that have already been processed by HMAC. Raises in case of length mismatch.
def fixed_length_secure_compare(a, b)
raise ArgumentError, "string length mismatch." unless a.bytesize == b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
module_function :fixed_length_secure_compare
# Constant time string comparison, for variable length strings.
#
# The values are first processed by SHA256, so that we don't leak length info
# via timing attacks.
def secure_compare(a, b)
fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b
end
module_function :secure_compare
end
end

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/symbol/starts_ends_with"
module ActiveSupport module ActiveSupport
# Wrapping an array in an +ArrayInquirer+ gives a friendlier way to check # Wrapping an array in an +ArrayInquirer+ gives a friendlier way to check
# its string-like contents: # its string-like contents:
@ -34,11 +36,11 @@ module ActiveSupport
private private
def respond_to_missing?(name, include_private = false) def respond_to_missing?(name, include_private = false)
(name[-1] == "?") || super name.end_with?("?") || super
end end
def method_missing(name, *args) def method_missing(name, *args)
if name[-1] == "?" if name.end_with?("?")
any?(name[0..-2]) any?(name[0..-2])
else else
super super

View File

@ -16,7 +16,7 @@ module ActiveSupport
# #
# bc = ActiveSupport::BacktraceCleaner.new # bc = ActiveSupport::BacktraceCleaner.new
# bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix # bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
# bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems # bc.add_silencer { |line| /puma|rubygems/.match?(line) } # skip any lines from puma or rubygems
# bc.clean(exception.backtrace) # perform the cleanup # bc.clean(exception.backtrace) # perform the cleanup
# #
# To reconfigure an existing BacktraceCleaner (like the default one in Rails) # To reconfigure an existing BacktraceCleaner (like the default one in Rails)
@ -65,7 +65,7 @@ module ActiveSupport
# for a given line, it will be excluded from the clean backtrace. # for a given line, it will be excluded from the clean backtrace.
# #
# # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb" # # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb"
# backtrace_cleaner.add_silencer { |line| line =~ /puma/ } # backtrace_cleaner.add_silencer { |line| /puma/.match?(line) }
def add_silencer(&block) def add_silencer(&block)
@silencers << block @silencers << block
end end
@ -91,7 +91,7 @@ module ActiveSupport
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) } gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
return if gems_paths.empty? return if gems_paths.empty?
gems_regexp = %r{(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)} gems_regexp = %r{\A(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)}
gems_result = '\3 (\4) \5' gems_result = '\3 (\4) \5'
add_filter { |line| line.sub(gems_regexp, gems_result) } add_filter { |line| line.sub(gems_regexp, gems_result) }
end end

View File

@ -41,7 +41,7 @@ module ActiveSupport
result = nil result = nil
ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield } ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
logger.send(options[:level], "%s (%.1fms)" % [ message, ms ]) logger.public_send(options[:level], "%s (%.1fms)" % [ message, ms ])
result result
else else
yield yield

View File

@ -4,10 +4,7 @@ require "active_support/concern"
require "active_support/descendants_tracker" require "active_support/descendants_tracker"
require "active_support/core_ext/array/extract_options" require "active_support/core_ext/array/extract_options"
require "active_support/core_ext/class/attribute" require "active_support/core_ext/class/attribute"
require "active_support/core_ext/kernel/reporting"
require "active_support/core_ext/kernel/singleton_class"
require "active_support/core_ext/string/filters" require "active_support/core_ext/string/filters"
require "active_support/deprecation"
require "thread" require "thread"
module ActiveSupport module ActiveSupport
@ -103,32 +100,6 @@ module ActiveSupport
env = Filters::Environment.new(self, false, nil) env = Filters::Environment.new(self, false, nil)
next_sequence = callbacks.compile next_sequence = callbacks.compile
invoke_sequence = Proc.new do
skipped = nil
while true
current = next_sequence
current.invoke_before(env)
if current.final?
env.value = !env.halted && (!block_given? || yield)
elsif current.skip?(env)
(skipped ||= []) << current
next_sequence = next_sequence.nested
next
else
next_sequence = next_sequence.nested
begin
target, block, method, *arguments = current.expand_call_template(env, invoke_sequence)
target.send(method, *arguments, &block)
ensure
next_sequence = current
end
end
current.invoke_after(env)
skipped.pop.invoke_after(env) while skipped && skipped.first
break env.value
end
end
# Common case: no 'around' callbacks defined # Common case: no 'around' callbacks defined
if next_sequence.final? if next_sequence.final?
next_sequence.invoke_before(env) next_sequence.invoke_before(env)
@ -136,6 +107,33 @@ module ActiveSupport
next_sequence.invoke_after(env) next_sequence.invoke_after(env)
env.value env.value
else else
invoke_sequence = Proc.new do
skipped = nil
while true
current = next_sequence
current.invoke_before(env)
if current.final?
env.value = !env.halted && (!block_given? || yield)
elsif current.skip?(env)
(skipped ||= []) << current
next_sequence = next_sequence.nested
next
else
next_sequence = next_sequence.nested
begin
target, block, method, *arguments = current.expand_call_template(env, invoke_sequence)
target.send(method, *arguments, &block)
ensure
next_sequence = current
end
end
current.invoke_after(env)
skipped.pop.invoke_after(env) while skipped&.first
break env.value
end
end
invoke_sequence.call invoke_sequence.call
end end
end end
@ -145,7 +143,7 @@ module ActiveSupport
# A hook invoked every time a before callback is halted. # A hook invoked every time a before callback is halted.
# This can be overridden in ActiveSupport::Callbacks implementors in order # This can be overridden in ActiveSupport::Callbacks implementors in order
# to provide better debugging/logging. # to provide better debugging/logging.
def halted_callback_hook(filter) def halted_callback_hook(filter, name)
end end
module Conditionals # :nodoc: module Conditionals # :nodoc:
@ -161,17 +159,17 @@ module ActiveSupport
Environment = Struct.new(:target, :halted, :value) Environment = Struct.new(:target, :halted, :value)
class Before class Before
def self.build(callback_sequence, user_callback, user_conditions, chain_config, filter) def self.build(callback_sequence, user_callback, user_conditions, chain_config, filter, name)
halted_lambda = chain_config[:terminator] halted_lambda = chain_config[:terminator]
if user_conditions.any? if user_conditions.any?
halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter) halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter, name)
else else
halting(callback_sequence, user_callback, halted_lambda, filter) halting(callback_sequence, user_callback, halted_lambda, filter, name)
end end
end end
def self.halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter) def self.halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter, name)
callback_sequence.before do |env| callback_sequence.before do |env|
target = env.target target = env.target
value = env.value value = env.value
@ -181,7 +179,7 @@ module ActiveSupport
result_lambda = -> { user_callback.call target, value } result_lambda = -> { user_callback.call target, value }
env.halted = halted_lambda.call(target, result_lambda) env.halted = halted_lambda.call(target, result_lambda)
if env.halted if env.halted
target.send :halted_callback_hook, filter target.send :halted_callback_hook, filter, name
end end
end end
@ -190,7 +188,7 @@ module ActiveSupport
end end
private_class_method :halting_and_conditional private_class_method :halting_and_conditional
def self.halting(callback_sequence, user_callback, halted_lambda, filter) def self.halting(callback_sequence, user_callback, halted_lambda, filter, name)
callback_sequence.before do |env| callback_sequence.before do |env|
target = env.target target = env.target
value = env.value value = env.value
@ -199,9 +197,8 @@ module ActiveSupport
unless halted unless halted
result_lambda = -> { user_callback.call target, value } result_lambda = -> { user_callback.call target, value }
env.halted = halted_lambda.call(target, result_lambda) env.halted = halted_lambda.call(target, result_lambda)
if env.halted if env.halted
target.send :halted_callback_hook, filter target.send :halted_callback_hook, filter, name
end end
end end
@ -300,8 +297,8 @@ module ActiveSupport
@kind = kind @kind = kind
@filter = filter @filter = filter
@key = compute_identifier filter @key = compute_identifier filter
@if = check_conditionals(Array(options[:if])) @if = check_conditionals(options[:if])
@unless = check_conditionals(Array(options[:unless])) @unless = check_conditionals(options[:unless])
end end
def filter; @key; end def filter; @key; end
@ -339,7 +336,7 @@ module ActiveSupport
case kind case kind
when :before when :before
Filters::Before.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config, @filter) Filters::Before.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config, @filter, name)
when :after when :after
Filters::After.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config) Filters::After.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config)
when :around when :around
@ -352,7 +349,13 @@ module ActiveSupport
end end
private private
EMPTY_ARRAY = [].freeze
private_constant :EMPTY_ARRAY
def check_conditionals(conditionals) def check_conditionals(conditionals)
return EMPTY_ARRAY if conditionals.blank?
conditionals = Array(conditionals)
if conditionals.any? { |c| c.is_a?(String) } if conditionals.any? { |c| c.is_a?(String) }
raise ArgumentError, <<-MSG.squish raise ArgumentError, <<-MSG.squish
Passing string to be evaluated in :if and :unless conditional Passing string to be evaluated in :if and :unless conditional
@ -361,7 +364,7 @@ module ActiveSupport
MSG MSG
end end
conditionals conditionals.freeze
end end
def compute_identifier(filter) def compute_identifier(filter)
@ -403,21 +406,17 @@ module ActiveSupport
# The actual invocation is left up to the caller to minimize # The actual invocation is left up to the caller to minimize
# call stack pollution. # call stack pollution.
def expand(target, value, block) def expand(target, value, block)
result = @arguments.map { |arg| expanded = [@override_target || target, @override_block || block, @method_name]
@arguments.each do |arg|
case arg case arg
when :value; value when :value then expanded << value
when :target; target when :target then expanded << target
when :block; block || raise(ArgumentError) when :block then expanded << (block || raise(ArgumentError))
end end
} end
result.unshift @method_name expanded
result.unshift @override_block || block
result.unshift @override_target || target
# target, block, method, *arguments = result
# target.send(method, *arguments, &block)
result
end end
# Return a lambda that will make this call when given the input # Return a lambda that will make this call when given the input
@ -845,8 +844,18 @@ module ActiveSupport
__callbacks[name.to_sym] __callbacks[name.to_sym]
end end
def set_callbacks(name, callbacks) # :nodoc: if Module.instance_method(:method_defined?).arity == 1 # Ruby 2.5 and older
self.__callbacks = __callbacks.merge(name.to_sym => callbacks) def set_callbacks(name, callbacks) # :nodoc:
self.__callbacks = __callbacks.merge(name.to_sym => callbacks)
end
else # Ruby 2.6 and newer
def set_callbacks(name, callbacks) # :nodoc:
unless singleton_class.method_defined?(:__callbacks, false)
self.__callbacks = __callbacks.dup
end
self.__callbacks[name.to_sym] = callbacks
self.__callbacks
end
end end
end end
end end

View File

@ -19,7 +19,7 @@ module ActiveSupport
# By using <tt>ActiveSupport::Concern</tt> the above module could instead be # By using <tt>ActiveSupport::Concern</tt> the above module could instead be
# written as: # written as:
# #
# require 'active_support/concern' # require "active_support/concern"
# #
# module M # module M
# extend ActiveSupport::Concern # extend ActiveSupport::Concern
@ -76,7 +76,7 @@ module ActiveSupport
# is the +Bar+ module, not the +Host+ class. With <tt>ActiveSupport::Concern</tt>, # is the +Bar+ module, not the +Host+ class. With <tt>ActiveSupport::Concern</tt>,
# module dependencies are properly resolved: # module dependencies are properly resolved:
# #
# require 'active_support/concern' # require "active_support/concern"
# #
# module Foo # module Foo
# extend ActiveSupport::Concern # extend ActiveSupport::Concern
@ -99,6 +99,14 @@ module ActiveSupport
# class Host # class Host
# include Bar # It works, now Bar takes care of its dependencies # include Bar # It works, now Bar takes care of its dependencies
# end # end
#
# === Prepending concerns
#
# Just like <tt>include</tt>, concerns also support <tt>prepend</tt> with a corresponding
# <tt>prepended do</tt> callback. <tt>module ClassMethods</tt> or <tt>class_methods do</tt> are
# prepended as well.
#
# <tt>prepend</tt> is also used for any dependencies.
module Concern module Concern
class MultipleIncludedBlocks < StandardError #:nodoc: class MultipleIncludedBlocks < StandardError #:nodoc:
def initialize def initialize
@ -106,6 +114,12 @@ module ActiveSupport
end end
end end
class MultiplePrependBlocks < StandardError #:nodoc:
def initialize
super "Cannot define multiple 'prepended' blocks for a Concern"
end
end
def self.extended(base) #:nodoc: def self.extended(base) #:nodoc:
base.instance_variable_set(:@_dependencies, []) base.instance_variable_set(:@_dependencies, [])
end end
@ -123,6 +137,19 @@ module ActiveSupport
end end
end end
def prepend_features(base) #:nodoc:
if base.instance_variable_defined?(:@_dependencies)
base.instance_variable_get(:@_dependencies).unshift self
false
else
return false if base < self
@_dependencies.each { |dep| base.prepend(dep) }
super
base.singleton_class.prepend const_get(:ClassMethods) if const_defined?(:ClassMethods)
base.class_eval(&@_prepended_block) if instance_variable_defined?(:@_prepended_block)
end
end
# Evaluate given block in context of base class, # Evaluate given block in context of base class,
# so that you can write class macros here. # so that you can write class macros here.
# When you define more than one +included+ block, it raises an exception. # When you define more than one +included+ block, it raises an exception.
@ -140,6 +167,23 @@ module ActiveSupport
end end
end end
# Evaluate given block in context of base class,
# so that you can write class macros here.
# When you define more than one +prepended+ block, it raises an exception.
def prepended(base = nil, &block)
if base.nil?
if instance_variable_defined?(:@_prepended_block)
if @_prepended_block.source_location != block.source_location
raise MultiplePrependBlocks
end
else
@_prepended_block = block
end
else
super
end
end
# Define class methods from given block. # Define class methods from given block.
# You can define private class methods as well. # You can define private class methods as well.
# #

View File

@ -5,7 +5,7 @@ require "active_support/ordered_options"
module ActiveSupport module ActiveSupport
# Configurable provides a <tt>config</tt> method to store and retrieve # Configurable provides a <tt>config</tt> method to store and retrieve
# configuration options as an <tt>OrderedHash</tt>. # configuration options as an <tt>OrderedOptions</tt>.
module Configurable module Configurable
extend ActiveSupport::Concern extend ActiveSupport::Concern
@ -124,9 +124,9 @@ module ActiveSupport
private :config_accessor private :config_accessor
end end
# Reads and writes attributes from a configuration <tt>OrderedHash</tt>. # Reads and writes attributes from a configuration <tt>OrderedOptions</tt>.
# #
# require 'active_support/configurable' # require "active_support/configurable"
# #
# class User # class User
# include ActiveSupport::Configurable # include ActiveSupport::Configurable

View File

@ -0,0 +1,46 @@
# frozen_string_literal: true
module ActiveSupport
# Reads a YAML configuration file, evaluating any ERB, then
# parsing the resulting YAML.
#
# Warns in case of YAML confusing characters, like invisible
# non-breaking spaces.
class ConfigurationFile # :nodoc:
class FormatError < StandardError; end
def initialize(content_path)
@content_path = content_path.to_s
@content = read content_path
end
def self.parse(content_path, **options)
new(content_path).parse(**options)
end
def parse(context: nil, **options)
YAML.load(render(context), **options) || {}
rescue Psych::SyntaxError => error
raise "YAML syntax error occurred while parsing #{@content_path}. " \
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
"Error: #{error.message}"
end
private
def read(content_path)
require "yaml"
require "erb"
File.read(content_path).tap do |content|
if content.include?("\u00A0")
warn "File contains invisible non-breaking spaces, you may want to remove those"
end
end
end
def render(context)
erb = ERB.new(@content).tap { |e| e.filename = @content_path }
context ? erb.result(context) : erb.result
end
end
end

View File

@ -10,7 +10,7 @@ class << Benchmark
# #
# Benchmark.ms { User.all } # Benchmark.ms { User.all }
# # => 0.074 # # => 0.074
def ms def ms(&block)
1000 * realtime { yield } 1000 * realtime(&block)
end end
end end

View File

@ -1,8 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/kernel/singleton_class"
require "active_support/core_ext/module/redefine_method" require "active_support/core_ext/module/redefine_method"
require "active_support/core_ext/array/extract_options"
class Class class Class
# Declare a class-level attribute whose value is inheritable by subclasses. # Declare a class-level attribute whose value is inheritable by subclasses.
@ -84,58 +82,50 @@ class Class
# To set a default value for the attribute, pass <tt>default:</tt>, like so: # To set a default value for the attribute, pass <tt>default:</tt>, like so:
# #
# class_attribute :settings, default: {} # class_attribute :settings, default: {}
def class_attribute( def class_attribute(*attrs, instance_accessor: true,
*attrs, instance_reader: instance_accessor, instance_writer: instance_accessor, instance_predicate: true, default: nil)
instance_accessor: true,
instance_reader: instance_accessor, class_methods, methods = [], []
instance_writer: instance_accessor,
instance_predicate: true,
default: nil
)
attrs.each do |name| attrs.each do |name|
singleton_class.silence_redefinition_of_method(name) unless name.is_a?(Symbol) || name.is_a?(String)
define_singleton_method(name) { default } raise TypeError, "#{name.inspect} is not a symbol nor a string"
singleton_class.silence_redefinition_of_method("#{name}?")
define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
ivar = "@#{name}".to_sym
singleton_class.silence_redefinition_of_method("#{name}=")
define_singleton_method("#{name}=") do |val|
redefine_singleton_method(name) { val }
if singleton_class?
class_eval do
redefine_method(name) do
if instance_variable_defined? ivar
instance_variable_get ivar
else
singleton_class.send name
end
end
end
end
val
end end
if instance_reader class_methods << <<~RUBY # In case the method exists and is not public
redefine_method(name) do silence_redefinition_of_method def #{name}
if instance_variable_defined?(ivar)
instance_variable_get ivar
else
self.class.public_send name
end
end end
RUBY
redefine_method("#{name}?") { !!public_send(name) } if instance_predicate methods << <<~RUBY if instance_reader
end silence_redefinition_of_method def #{name}
defined?(@#{name}) ? @#{name} : self.class.#{name}
end
RUBY
if instance_writer class_methods << <<~RUBY
redefine_method("#{name}=") do |val| silence_redefinition_of_method def #{name}=(value)
instance_variable_set ivar, val redefine_method(:#{name}) { value } if singleton_class?
redefine_singleton_method(:#{name}) { value }
value
end
RUBY
methods << <<~RUBY if instance_writer
silence_redefinition_of_method(:#{name}=)
attr_writer :#{name}
RUBY
if instance_predicate
class_methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
if instance_reader
methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
end end
end end
end end
location = caller_locations(1, 1).first
class_eval(["class << self", *class_methods, "end", *methods].join(";").tr("\n", ";"), location.path, location.lineno)
attrs.each { |name| public_send("#{name}=", default) }
end end
end end

View File

@ -0,0 +1,33 @@
# frozen_string_literal: true
class Class
# Returns an array with all classes that are < than its receiver.
#
# class C; end
# C.descendants # => []
#
# class B < C; end
# C.descendants # => [B]
#
# class A < B; end
# C.descendants # => [B, A]
#
# class D < C; end
# C.descendants # => [B, A, D]
def descendants
ObjectSpace.each_object(singleton_class).reject do |k|
k.singleton_class? || k == self
end
end
# Returns an array with the direct children of +self+.
#
# class Foo; end
# class Bar < Foo; end
# class Baz < Bar; end
#
# Foo.subclasses # => [Bar]
def subclasses
descendants.select { |descendant| descendant.superclass == self }
end
end

View File

@ -10,6 +10,7 @@ class Date
short: "%d %b", short: "%d %b",
long: "%B %d, %Y", long: "%B %d, %Y",
db: "%Y-%m-%d", db: "%Y-%m-%d",
inspect: "%Y-%m-%d",
number: "%Y%m%d", number: "%Y%m%d",
long_ordinal: lambda { |date| long_ordinal: lambda { |date|
day_format = ActiveSupport::Inflector.ordinalize(date.day) day_format = ActiveSupport::Inflector.ordinalize(date.day)
@ -80,7 +81,7 @@ class Date
# If the *application's* timezone is needed, then use +in_time_zone+ instead. # If the *application's* timezone is needed, then use +in_time_zone+ instead.
def to_time(form = :local) def to_time(form = :local)
raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form) raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
::Time.send(form, year, month, day) ::Time.public_send(form, year, month, day)
end end
silence_redefinition_of_method :xmlschema silence_redefinition_of_method :xmlschema

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/object/try" require "active_support/core_ext/object/try"
require "active_support/core_ext/date_time/conversions"
module DateAndTime module DateAndTime
module Calculations module Calculations
@ -30,6 +31,18 @@ module DateAndTime
to_date == ::Date.current to_date == ::Date.current
end end
# Returns true if the date/time is tomorrow.
def tomorrow?
to_date == ::Date.current.tomorrow
end
alias :next_day? :tomorrow?
# Returns true if the date/time is yesterday.
def yesterday?
to_date == ::Date.current.yesterday
end
alias :prev_day? :yesterday?
# Returns true if the date/time is in the past. # Returns true if the date/time is in the past.
def past? def past?
self < self.class.current self < self.class.current

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
require "active_support/core_ext/module/attribute_accessors"
module DateAndTime
module Compatibility
# If true, +to_time+ preserves the timezone offset of receiver.
#
# NOTE: With Ruby 2.4+ the default for +to_time+ changed from
# converting to the local system time, to preserving the offset
# of the receiver. For backwards compatibility we're overriding
# this behavior, but new apps will have an initializer that sets
# this to true, because the new behavior is preferred.
mattr_accessor :preserve_timezone, instance_writer: false, default: false
# Change the output of <tt>ActiveSupport::TimeZone.utc_to_local</tt>.
#
# When `true`, it returns local times with an UTC offset, with `false` local
# times are returned as UTC.
#
# # Given this zone:
# zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
#
# # With `utc_to_local_returns_utc_offset_times = false`, local time is converted to UTC:
# zone.utc_to_local(Time.utc(2000, 1)) # => 1999-12-31 19:00:00 UTC
#
# # With `utc_to_local_returns_utc_offset_times = true`, local time is returned with UTC offset:
# zone.utc_to_local(Time.utc(2000, 1)) # => 1999-12-31 19:00:00 -0500
mattr_accessor :utc_to_local_returns_utc_offset_times, instance_writer: false, default: false
end
end

View File

@ -44,7 +44,8 @@ module Enumerable
end end
end end
# Convert an enumerable to a hash keying it by the block return value. # Convert an enumerable to a hash, using the block result as the key and the
# element as the value.
# #
# people.index_by(&:login) # people.index_by(&:login)
# # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...} # # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...}
@ -61,12 +62,19 @@ module Enumerable
end end
end end
# Convert an enumerable to a hash keying it with the enumerable items and with the values returned in the block. # Convert an enumerable to a hash, using the element as the key and the block
# result as the value.
# #
# post = Post.new(title: "hey there", body: "what's up?") # post = Post.new(title: "hey there", body: "what's up?")
# #
# %i( title body ).index_with { |attr_name| post.public_send(attr_name) } # %i( title body ).index_with { |attr_name| post.public_send(attr_name) }
# # => { title: "hey there", body: "what's up?" } # # => { title: "hey there", body: "what's up?" }
#
# If an argument is passed instead of a block, it will be used as the value
# for all elements:
#
# %i( created_at updated_at ).index_with(Time.now)
# # => { created_at: 2020-03-09 22:31:47, updated_at: 2020-03-09 22:31:47 }
def index_with(default = INDEX_WITH_DEFAULT) def index_with(default = INDEX_WITH_DEFAULT)
if block_given? if block_given?
result = {} result = {}
@ -134,7 +142,7 @@ module Enumerable
excluding(*elements) excluding(*elements)
end end
# Convert an enumerable to an array based on the given key. # Extract the given key from each element in the enumerable.
# #
# [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name) # [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name)
# # => ["David", "Rafael", "Aaron"] # # => ["David", "Rafael", "Aaron"]
@ -145,9 +153,62 @@ module Enumerable
if keys.many? if keys.many?
map { |element| keys.map { |key| element[key] } } map { |element| keys.map { |key| element[key] } }
else else
map { |element| element[keys.first] } key = keys.first
map { |element| element[key] }
end end
end end
# Extract the given key from the first element in the enumerable.
#
# [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pick(:name)
# # => "David"
#
# [{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pick(:id, :name)
# # => [1, "David"]
def pick(*keys)
return if none?
if keys.many?
keys.map { |key| first[key] }
else
first[keys.first]
end
end
# Returns a new +Array+ without the blank items.
# Uses Object#blank? for determining if an item is blank.
#
# [1, "", nil, 2, " ", [], {}, false, true].compact_blank
# # => [1, 2, true]
#
# Set.new([nil, "", 1, 2])
# # => [2, 1] (or [1, 2])
#
# When called on a +Hash+, returns a new +Hash+ without the blank values.
#
# { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
# #=> { b: 1, f: true }
def compact_blank
reject(&:blank?)
end
end
class Hash
# Hash#reject has its own definition, so this needs one too.
def compact_blank #:nodoc:
reject { |_k, v| v.blank? }
end
# Removes all blank values from the +Hash+ in place and returns self.
# Uses Object#blank? for determining if a value is blank.
#
# h = { a: "", b: 1, c: nil, d: [], e: false, f: true }
# h.compact_blank!
# # => { b: 1, f: true }
def compact_blank!
# use delete_if rather than reject! because it always returns self even if nothing changed
delete_if { |_k, v| v.blank? }
end
end end
class Range #:nodoc: class Range #:nodoc:
@ -185,4 +246,15 @@ class Array #:nodoc:
super super
end end
end end
# Removes all blank elements from the +Array+ in place and returns self.
# Uses Object#blank? for determining if an item is blank.
#
# a = [1, "", nil, 2, " ", [], {}, false, true]
# a.compact_blank!
# # => [1, 2, true]
def compact_blank!
# use delete_if rather than reject! because it always returns self even if nothing changed
delete_if(&:blank?)
end
end end

View File

@ -1,10 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/xml_mini" require "active_support/xml_mini"
require "active_support/time"
require "active_support/core_ext/object/blank" require "active_support/core_ext/object/blank"
require "active_support/core_ext/object/to_param" require "active_support/core_ext/object/to_param"
require "active_support/core_ext/object/to_query" require "active_support/core_ext/object/to_query"
require "active_support/core_ext/object/try"
require "active_support/core_ext/array/wrap" require "active_support/core_ext/array/wrap"
require "active_support/core_ext/hash/reverse_merge" require "active_support/core_ext/hash/reverse_merge"
require "active_support/core_ext/string/inflections" require "active_support/core_ext/string/inflections"
@ -208,7 +208,7 @@ module ActiveSupport
elsif become_empty_string?(value) elsif become_empty_string?(value)
"" ""
elsif become_hash?(value) elsif become_hash?(value)
xml_value = Hash[value.map { |k, v| [k, deep_to_h(v)] }] xml_value = value.transform_values { |v| deep_to_h(v) }
# Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with # Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with
# how multipart uploaded files from HTML appear # how multipart uploaded files from HTML appear

View File

@ -21,7 +21,7 @@ class Hash
end end
private private
# support methods for deep transforming nested hashes and arrays # Support methods for deep transforming nested hashes and arrays.
def _deep_transform_values_in_object(object, &block) def _deep_transform_values_in_object(object, &block)
case object case object
when Hash when Hash

View File

@ -11,7 +11,7 @@ class Hash
# @person.update(params[:person].except(:admin)) # @person.update(params[:person].except(:admin))
def except(*keys) def except(*keys)
slice(*self.keys - keys) slice(*self.keys - keys)
end end unless method_defined?(:except)
# Removes the given keys from hash and returns it. # Removes the given keys from hash and returns it.
# hash = { a: true, b: false, c: nil } # hash = { a: true, b: false, c: nil }

View File

@ -112,7 +112,7 @@ class Hash
end end
private private
# support methods for deep transforming nested hashes and arrays # Support methods for deep transforming nested hashes and arrays.
def _deep_transform_keys_in_object(object, &block) def _deep_transform_keys_in_object(object, &block)
case object case object
when Hash when Hash

View File

@ -18,8 +18,9 @@ class Hash
# Removes and returns the key/value pairs matching the given keys. # Removes and returns the key/value pairs matching the given keys.
# #
# { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b) # => {:a=>1, :b=>2} # hash = { a: 1, b: 2, c: 3, d: 4 }
# { a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1} # hash.extract!(:a, :b) # => {:a=>1, :b=>2}
# hash # => {:c=>3, :d=>4}
def extract!(*keys) def extract!(*keys)
keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) } keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
end end

View File

@ -4,6 +4,6 @@ class LoadError
# Returns true if the given path name (except perhaps for the ".rb" # Returns true if the given path name (except perhaps for the ".rb"
# extension) is the missing file which caused the exception to be raised. # extension) is the missing file which caused the exception to be raised.
def is_missing?(location) def is_missing?(location)
location.sub(/\.rb$/, "") == path.to_s.sub(/\.rb$/, "") location.delete_suffix(".rb") == path.to_s.delete_suffix(".rb")
end end
end end

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/string/inflections"
module ActiveSupport module ActiveSupport
module MarshalWithAutoloading # :nodoc: module MarshalWithAutoloading # :nodoc:
def load(source, proc = nil) def load(source, proc = nil)

View File

@ -28,9 +28,9 @@ class Module
end end
def attr_internal_define(attr_name, type) def attr_internal_define(attr_name, type)
internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, "") internal_name = attr_internal_ivar_name(attr_name).delete_prefix("@")
# use native attr_* methods as they are faster on some Ruby implementations # use native attr_* methods as they are faster on some Ruby implementations
send("attr_#{type}", internal_name) public_send("attr_#{type}", internal_name)
attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer
alias_method attr_name, internal_name alias_method attr_name, internal_name
remove_method internal_name remove_method internal_name

View File

@ -48,28 +48,25 @@ class Module
# end # end
# #
# Person.new.hair_colors # => [:brown, :black, :blonde, :red] # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
def mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil) def mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil, location: nil)
raise TypeError, "module attributes should be defined directly on class, not singleton" if singleton_class?
location ||= caller_locations(1, 1).first
definition = []
syms.each do |sym| syms.each do |sym|
raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym) raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym)
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@#{sym} = nil unless defined? @@#{sym}
def self.#{sym} definition << "def self.#{sym}; @@#{sym}; end"
@@#{sym}
end
EOS
if instance_reader && instance_accessor if instance_reader && instance_accessor
class_eval(<<-EOS, __FILE__, __LINE__ + 1) definition << "def #{sym}; @@#{sym}; end"
def #{sym}
@@#{sym}
end
EOS
end end
sym_default_value = (block_given? && default.nil?) ? yield : default sym_default_value = (block_given? && default.nil?) ? yield : default
class_variable_set("@@#{sym}", sym_default_value) unless sym_default_value.nil? class_variable_set("@@#{sym}", sym_default_value) unless sym_default_value.nil? && class_variable_defined?("@@#{sym}")
end end
module_eval(definition.join(";"), location.path, location.lineno)
end end
alias :cattr_reader :mattr_reader alias :cattr_reader :mattr_reader
@ -115,28 +112,24 @@ class Module
# end # end
# #
# Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red] # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
def mattr_writer(*syms, instance_writer: true, instance_accessor: true, default: nil) def mattr_writer(*syms, instance_writer: true, instance_accessor: true, default: nil, location: nil)
raise TypeError, "module attributes should be defined directly on class, not singleton" if singleton_class?
location ||= caller_locations(1, 1).first
definition = []
syms.each do |sym| syms.each do |sym|
raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym) raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym)
class_eval(<<-EOS, __FILE__, __LINE__ + 1) definition << "def self.#{sym}=(val); @@#{sym} = val; end"
@@#{sym} = nil unless defined? @@#{sym}
def self.#{sym}=(obj)
@@#{sym} = obj
end
EOS
if instance_writer && instance_accessor if instance_writer && instance_accessor
class_eval(<<-EOS, __FILE__, __LINE__ + 1) definition << "def #{sym}=(val); @@#{sym} = val; end"
def #{sym}=(obj)
@@#{sym} = obj
end
EOS
end end
sym_default_value = (block_given? && default.nil?) ? yield : default sym_default_value = (block_given? && default.nil?) ? yield : default
send("#{sym}=", sym_default_value) unless sym_default_value.nil? class_variable_set("@@#{sym}", sym_default_value) unless sym_default_value.nil? && class_variable_defined?("@@#{sym}")
end end
module_eval(definition.join(";"), location.path, location.lineno)
end end
alias :cattr_writer :mattr_writer alias :cattr_writer :mattr_writer
@ -205,8 +198,9 @@ class Module
# #
# Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red] # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
def mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil, &blk) def mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil, &blk)
mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor, default: default, &blk) location = caller_locations(1, 1).first
mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor, default: default) mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor, default: default, location: location, &blk)
mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor, default: default, location: location)
end end
alias :cattr_accessor :mattr_accessor alias :cattr_accessor :mattr_accessor
end end

View File

@ -33,7 +33,7 @@ class Module
# end # end
# #
# Current.new.user # => NoMethodError # Current.new.user # => NoMethodError
def thread_mattr_reader(*syms, instance_reader: true, instance_accessor: true) # :nodoc: def thread_mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil) # :nodoc:
syms.each do |sym| syms.each do |sym|
raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym) raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym)
@ -52,6 +52,8 @@ class Module
end end
EOS EOS
end end
Thread.current["attr_" + name + "_#{sym}"] = default unless default.nil?
end end
end end
alias :thread_cattr_reader :thread_mattr_reader alias :thread_cattr_reader :thread_mattr_reader
@ -74,7 +76,7 @@ class Module
# end # end
# #
# Current.new.user = "DHH" # => NoMethodError # Current.new.user = "DHH" # => NoMethodError
def thread_mattr_writer(*syms, instance_writer: true, instance_accessor: true) # :nodoc: def thread_mattr_writer(*syms, instance_writer: true, instance_accessor: true, default: nil) # :nodoc:
syms.each do |sym| syms.each do |sym|
raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym) raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym)
@ -93,6 +95,8 @@ class Module
end end
EOS EOS
end end
public_send("#{sym}=", default) unless default.nil?
end end
end end
alias :thread_cattr_writer :thread_mattr_writer alias :thread_cattr_writer :thread_mattr_writer
@ -136,8 +140,8 @@ class Module
# #
# Current.new.user = "DHH" # => NoMethodError # Current.new.user = "DHH" # => NoMethodError
# Current.new.user # => NoMethodError # Current.new.user # => NoMethodError
def thread_mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true) def thread_mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil)
thread_mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor) thread_mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor, default: default)
thread_mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor) thread_mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor)
end end
alias :thread_cattr_accessor :thread_mattr_accessor alias :thread_cattr_accessor :thread_mattr_accessor

View File

@ -104,10 +104,16 @@ class Module
# * grok the behavior of our class in one glance, # * grok the behavior of our class in one glance,
# * clean up monolithic junk-drawer classes by separating their concerns, and # * clean up monolithic junk-drawer classes by separating their concerns, and
# * stop leaning on protected/private for crude "this is internal stuff" modularity. # * stop leaning on protected/private for crude "this is internal stuff" modularity.
#
# === Prepending concerning
#
# <tt>concerning</tt> supports a <tt>prepend: true</tt> argument which will <tt>prepend</tt> the
# concern instead of using <tt>include</tt> for it.
module Concerning module Concerning
# Define a new concern and mix it in. # Define a new concern and mix it in.
def concerning(topic, &block) def concerning(topic, prepend: false, &block)
include concern(topic, &block) method = prepend ? :prepend : :include
__send__(method, concern(topic, &block))
end end
# A low-cruft shortcut to define a concern. # A low-cruft shortcut to define a concern.

View File

@ -170,7 +170,7 @@ class Module
# The target method must be public, otherwise it will raise +NoMethodError+. # The target method must be public, otherwise it will raise +NoMethodError+.
def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil) def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil)
unless to unless to
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter)." raise ArgumentError, "Delegation needs a target. Supply a keyword argument 'to' (e.g. delegate :hello, to: :greeter)."
end end
if prefix == true && /^[^a-z_]/.match?(to) if prefix == true && /^[^a-z_]/.match?(to)
@ -190,7 +190,13 @@ class Module
to = to.to_s to = to.to_s
to = "self.#{to}" if DELEGATION_RESERVED_METHOD_NAMES.include?(to) to = "self.#{to}" if DELEGATION_RESERVED_METHOD_NAMES.include?(to)
method_names = methods.map do |method| method_def = []
method_names = []
methods.map do |method|
method_name = prefix ? "#{method_prefix}#{method}" : method
method_names << method_name.to_sym
# Attribute writer methods only accept one argument. Makes sure []= # Attribute writer methods only accept one argument. Makes sure []=
# methods still accept two arguments. # methods still accept two arguments.
definition = if /[^\]]=$/.match?(method) definition = if /[^\]]=$/.match?(method)
@ -209,34 +215,33 @@ class Module
# whereas conceptually, from the user point of view, the delegator should # whereas conceptually, from the user point of view, the delegator should
# be doing one call. # be doing one call.
if allow_nil if allow_nil
method_def = [ method = method.to_s
"def #{method_prefix}#{method}(#{definition})",
"_ = #{to}",
"if !_.nil? || nil.respond_to?(:#{method})",
" _.#{method}(#{definition})",
"end",
"end"
].join ";"
else
exception = %(raise DelegationError, "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
method_def = [ method_def <<
"def #{method_prefix}#{method}(#{definition})", "def #{method_name}(#{definition})" <<
" _ = #{to}", " _ = #{to}" <<
" _.#{method}(#{definition})", " if !_.nil? || nil.respond_to?(:#{method})" <<
"rescue NoMethodError => e", " _.#{method}(#{definition})" <<
" if _.nil? && e.name == :#{method}", " end" <<
" #{exception}", "end"
" else", else
" raise", method = method.to_s
" end", method_name = method_name.to_s
method_def <<
"def #{method_name}(#{definition})" <<
" _ = #{to}" <<
" _.#{method}(#{definition})" <<
"rescue NoMethodError => e" <<
" if _.nil? && e.name == :#{method}" <<
%( raise DelegationError, "#{self}##{method_name} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}") <<
" else" <<
" raise" <<
" end" <<
"end" "end"
].join ";"
end end
module_eval(method_def, file, line)
end end
module_eval(method_def.join(";"), file, line)
private(*method_names) if private private(*method_names) if private
method_names method_names
end end
@ -280,13 +285,14 @@ class Module
# variables, methods, constants, etc. # variables, methods, constants, etc.
# #
# The delegated method must be public on the target, otherwise it will # The delegated method must be public on the target, otherwise it will
# raise +NoMethodError+. # raise +DelegationError+. If you wish to instead return +nil+,
# use the <tt>:allow_nil</tt> option.
# #
# The <tt>marshal_dump</tt> and <tt>_dump</tt> methods are exempt from # The <tt>marshal_dump</tt> and <tt>_dump</tt> methods are exempt from
# delegation due to possible interference when calling # delegation due to possible interference when calling
# <tt>Marshal.dump(object)</tt>, should the delegation target method # <tt>Marshal.dump(object)</tt>, should the delegation target method
# of <tt>object</tt> add or remove instance variables. # of <tt>object</tt> add or remove instance variables.
def delegate_missing_to(target) def delegate_missing_to(target, allow_nil: nil)
target = target.to_s target = target.to_s
target = "self.#{target}" if DELEGATION_RESERVED_METHOD_NAMES.include?(target) target = "self.#{target}" if DELEGATION_RESERVED_METHOD_NAMES.include?(target)
@ -307,7 +313,11 @@ class Module
super super
rescue NoMethodError rescue NoMethodError
if #{target}.nil? if #{target}.nil?
raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil" if #{allow_nil == true}
nil
else
raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil"
end
else else
raise raise
end end

View File

@ -11,20 +11,12 @@ class Module
if defined?(@parent_name) if defined?(@parent_name)
@parent_name @parent_name
else else
parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil parent_name = name =~ /::[^:]+\z/ ? -$` : nil
@parent_name = parent_name unless frozen? @parent_name = parent_name unless frozen?
parent_name parent_name
end end
end end
def parent_name
ActiveSupport::Deprecation.warn(<<-MSG.squish)
`Module#parent_name` has been renamed to `module_parent_name`.
`parent_name` is deprecated and will be removed in Rails 6.1.
MSG
module_parent_name
end
# Returns the module which contains this one according to its name. # Returns the module which contains this one according to its name.
# #
# module M # module M
@ -44,14 +36,6 @@ class Module
module_parent_name ? ActiveSupport::Inflector.constantize(module_parent_name) : Object module_parent_name ? ActiveSupport::Inflector.constantize(module_parent_name) : Object
end end
def parent
ActiveSupport::Deprecation.warn(<<-MSG.squish)
`Module#parent` has been renamed to `module_parent`.
`parent` is deprecated and will be removed in Rails 6.1.
MSG
module_parent
end
# Returns all the parents of this module according to its name, ordered from # Returns all the parents of this module according to its name, ordered from
# nested outwards. The receiver is not contained within the result. # nested outwards. The receiver is not contained within the result.
# #
@ -76,12 +60,4 @@ class Module
parents << Object unless parents.include? Object parents << Object unless parents.include? Object
parents parents
end end
def parents
ActiveSupport::Deprecation.warn(<<-MSG.squish)
`Module#parents` has been renamed to `module_parents`.
`parents` is deprecated and will be removed in Rails 6.1.
MSG
module_parents
end
end end

View File

@ -14,9 +14,22 @@ class NameError
# It extends NameError#message with spell corrections which are SLOW. # It extends NameError#message with spell corrections which are SLOW.
# We should use original_message message instead. # We should use original_message message instead.
message = respond_to?(:original_message) ? original_message : self.message message = respond_to?(:original_message) ? original_message : self.message
return unless message.start_with?("uninitialized constant ")
if /undefined local variable or method/ !~ message receiver = begin
$1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message self.receiver
rescue ArgumentError
nil
end
if receiver == Object
name.to_s
elsif receiver
"#{real_mod_name(receiver)}::#{self.name}"
else
if match = message.match(/((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/)
match[1]
end
end end
end end
@ -35,4 +48,18 @@ class NameError
missing_name == name.to_s missing_name == name.to_s
end end
end end
private
UNBOUND_METHOD_MODULE_NAME = Module.instance_method(:name)
private_constant :UNBOUND_METHOD_MODULE_NAME
if UnboundMethod.method_defined?(:bind_call)
def real_mod_name(mod)
UNBOUND_METHOD_MODULE_NAME.bind_call(mod)
end
else
def real_mod_name(mod)
UNBOUND_METHOD_MODULE_NAME.bind(mod).call
end
end
end end

Some files were not shown because too many files have changed in this diff Show More