Skip to content

Commit

Permalink
Partially add ActiveSupport and Concurrent Ruby gems.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Sep 14, 2018
1 parent 76b41ba commit a4d9b48
Show file tree
Hide file tree
Showing 28 changed files with 1,610 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
# Unignore vendored gems
!**/vendor/bundle-standalone/ruby/*/gems/*/lib

# Ignore backports gem (we don't need all files)
# Ignore partially included gems where we don't need all files
**/vendor/bundle-standalone/ruby/*/gems/activesupport-*/lib
**/vendor/bundle-standalone/ruby/*/gems/concurrent-ruby-*/lib
**/vendor/bundle-standalone/ruby/*/gems/backports-*/lib
**/vendor/bundle-standalone/ruby/*/gems/i18n-*/lib
**/vendor/bundle-standalone/ruby/*/gems/minitest-*/lib
**/vendor/bundle-standalone/ruby/*/gems/thread_safe-*/lib
**/vendor/bundle-standalone/ruby/*/gems/tzinfo-*/lib

# Ignore `bin` contents (again).
/bin
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/vendor/Gemfile
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"
14 changes: 14 additions & 0 deletions Library/Homebrew/vendor/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
backports (3.11.4)
concurrent-ruby (1.0.5)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
plist (3.4.0)
ruby-macho (2.0.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activesupport
backports
concurrent-ruby
plist
ruby-macho

Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/vendor/bundle-standalone/bundler/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
ruby_version = RbConfig::CONFIG["ruby_version"]
path = File.expand_path('..', __FILE__)
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.0.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.1.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.11.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thread_safe-0.3.6/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-1.2.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-5.2.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/backports-3.11.4/lib"
$:.unshift "#{path}/"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.4.0/lib"
Expand Down
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
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
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
Loading

0 comments on commit a4d9b48

Please sign in to comment.