-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially add ActiveSupport and Concurrent Ruby gems.
- Loading branch information
1 parent
76b41ba
commit a4d9b48
Showing
28 changed files
with
1,610 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "activesupport" | ||
gem "concurrent-ruby" | ||
gem "backports" | ||
gem "plist" | ||
gem "ruby-macho" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...tandalone/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/core_ext/object/blank.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/core_ext/regexp" | ||
require "concurrent/map" | ||
|
||
class Object | ||
# An object is blank if it's false, empty, or a whitespace string. | ||
# For example, +false+, '', ' ', +nil+, [], and {} are all blank. | ||
# | ||
# This simplifies | ||
# | ||
# !address || address.empty? | ||
# | ||
# to | ||
# | ||
# address.blank? | ||
# | ||
# @return [true, false] | ||
def blank? | ||
respond_to?(:empty?) ? !!empty? : !self | ||
end | ||
|
||
# An object is present if it's not blank. | ||
# | ||
# @return [true, false] | ||
def present? | ||
!blank? | ||
end | ||
|
||
# Returns the receiver if it's present otherwise returns +nil+. | ||
# <tt>object.presence</tt> is equivalent to | ||
# | ||
# object.present? ? object : nil | ||
# | ||
# For example, something like | ||
# | ||
# state = params[:state] if params[:state].present? | ||
# country = params[:country] if params[:country].present? | ||
# region = state || country || 'US' | ||
# | ||
# becomes | ||
# | ||
# region = params[:state].presence || params[:country].presence || 'US' | ||
# | ||
# @return [Object] | ||
def presence | ||
self if present? | ||
end | ||
end | ||
|
||
class NilClass | ||
# +nil+ is blank: | ||
# | ||
# nil.blank? # => true | ||
# | ||
# @return [true] | ||
def blank? | ||
true | ||
end | ||
end | ||
|
||
class FalseClass | ||
# +false+ is blank: | ||
# | ||
# false.blank? # => true | ||
# | ||
# @return [true] | ||
def blank? | ||
true | ||
end | ||
end | ||
|
||
class TrueClass | ||
# +true+ is not blank: | ||
# | ||
# true.blank? # => false | ||
# | ||
# @return [false] | ||
def blank? | ||
false | ||
end | ||
end | ||
|
||
class Array | ||
# An array is blank if it's empty: | ||
# | ||
# [].blank? # => true | ||
# [1,2,3].blank? # => false | ||
# | ||
# @return [true, false] | ||
alias_method :blank?, :empty? | ||
end | ||
|
||
class Hash | ||
# A hash is blank if it's empty: | ||
# | ||
# {}.blank? # => true | ||
# { key: 'value' }.blank? # => false | ||
# | ||
# @return [true, false] | ||
alias_method :blank?, :empty? | ||
end | ||
|
||
class String | ||
BLANK_RE = /\A[[:space:]]*\z/ | ||
ENCODED_BLANKS = Concurrent::Map.new do |h, enc| | ||
h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING) | ||
end | ||
|
||
# A string is blank if it's empty or contains whitespaces only: | ||
# | ||
# ''.blank? # => true | ||
# ' '.blank? # => true | ||
# "\t\n\r".blank? # => true | ||
# ' blah '.blank? # => false | ||
# | ||
# Unicode whitespace is supported: | ||
# | ||
# "\u00a0".blank? # => true | ||
# | ||
# @return [true, false] | ||
def blank? | ||
# The regexp that matches blank strings is expensive. For the case of empty | ||
# strings we can speed up this method (~3.5x) with an empty? call. The | ||
# penalty for the rest of strings is marginal. | ||
empty? || | ||
begin | ||
BLANK_RE.match?(self) | ||
rescue Encoding::CompatibilityError | ||
ENCODED_BLANKS[self.encoding].match?(self) | ||
end | ||
end | ||
end | ||
|
||
class Numeric #:nodoc: | ||
# No number is blank: | ||
# | ||
# 1.blank? # => false | ||
# 0.blank? # => false | ||
# | ||
# @return [false] | ||
def blank? | ||
false | ||
end | ||
end | ||
|
||
class Time #:nodoc: | ||
# No Time is blank: | ||
# | ||
# Time.now.blank? # => false | ||
# | ||
# @return [false] | ||
def blank? | ||
false | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
...ndle-standalone/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/core_ext/regexp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Regexp #:nodoc: | ||
def multiline? | ||
options & MULTILINE == MULTILINE | ||
end | ||
|
||
def match?(string, pos = 0) | ||
!!match(string, pos) | ||
end unless //.respond_to?(:match?) | ||
end |
66 changes: 66 additions & 0 deletions
66
...ne/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/collection/map/mri_map_backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'thread' | ||
require 'concurrent/collection/map/non_concurrent_map_backend' | ||
|
||
module Concurrent | ||
|
||
# @!visibility private | ||
module Collection | ||
|
||
# @!visibility private | ||
class MriMapBackend < NonConcurrentMapBackend | ||
|
||
def initialize(options = nil) | ||
super(options) | ||
@write_lock = Mutex.new | ||
end | ||
|
||
def []=(key, value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def compute_if_absent(key) | ||
if stored_value = _get(key) # fast non-blocking path for the most likely case | ||
stored_value | ||
else | ||
@write_lock.synchronize { super } | ||
end | ||
end | ||
|
||
def compute_if_present(key) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def compute(key) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def merge_pair(key, value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def replace_pair(key, old_value, new_value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def replace_if_exists(key, new_value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def get_and_set(key, value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def delete(key) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def delete_pair(key, value) | ||
@write_lock.synchronize { super } | ||
end | ||
|
||
def clear | ||
@write_lock.synchronize { super } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.