brew vendor-gems: commit updates.

This commit is contained in:
Mike McQuaid 2018-12-21 10:54:26 +00:00
parent f287c3240e
commit 0204a38f0c
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
35 changed files with 70 additions and 45 deletions

View File

@ -4,7 +4,7 @@ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
ruby_version = RbConfig::CONFIG["ruby_version"] ruby_version = RbConfig::CONFIG["ruby_version"]
path = File.expand_path('..', __FILE__) path = File.expand_path('..', __FILE__)
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.4/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.2.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.3.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.11.3/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/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/tzinfo-1.2.5/lib"

View File

@ -1,37 +0,0 @@
class Hash
def slice(*keep_keys)
h = {}
keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
h
end unless Hash.method_defined?(:slice)
def except(*less_keys)
slice(*keys - less_keys)
end unless Hash.method_defined?(:except)
def deep_symbolize_keys
inject({}) { |result, (key, value)|
value = value.deep_symbolize_keys if value.is_a?(Hash)
result[(key.to_sym rescue key) || key] = value
result
}
end unless Hash.method_defined?(:deep_symbolize_keys)
def deep_stringify_keys
inject({}) { |result, (key, value)|
value = value.deep_stringify_keys if value.is_a?(Hash)
result[key.to_s] = value
result
}
end unless Hash.method_defined?(:deep_stringify_keys)
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
MERGER = proc do |key, v1, v2|
Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
end
def deep_merge!(data)
merge!(data, &MERGER)
end unless Hash.method_defined?(:deep_merge!)
end

View File

@ -362,7 +362,18 @@ module I18n
else else
keys = key.to_s.split(separator) keys = key.to_s.split(separator)
keys.delete('') keys.delete('')
keys.map! { |k| k.to_sym } keys.map! do |k|
case k
when /\A[-+]?\d+\z/ # integer
k.to_i
when 'true'
true
when 'false'
false
else
k.to_sym
end
end
keys keys
end end
end end

View File

@ -7,6 +7,7 @@ require 'i18n/core_ext/hash'
module I18n module I18n
module Backend module Backend
module Base module Base
using I18n::HashRefinements
include I18n::Backend::Transliterator include I18n::Backend::Transliterator
# Accepts a list of paths to translation files. Loads translations from # Accepts a list of paths to translation files. Loads translations from

View File

@ -17,6 +17,8 @@ module I18n
# The implementation assumes that all backends added to the Chain implement # The implementation assumes that all backends added to the Chain implement
# a lookup method with the same API as Simple backend does. # a lookup method with the same API as Simple backend does.
class Chain class Chain
using I18n::HashRefinements
module Implementation module Implementation
include Base include Base

View File

@ -31,6 +31,8 @@ module I18n
# Without it strings containing periods (".") will not be translated. # Without it strings containing periods (".") will not be translated.
module Gettext module Gettext
using I18n::HashRefinements
class PoData < Hash class PoData < Hash
def set_comment(msgid_or_sym, comment) def set_comment(msgid_or_sym, comment)
# ignore # ignore

View File

@ -67,6 +67,8 @@ module I18n
# #
# This is useful if you are using a KeyValue backend chained to a Simple backend. # This is useful if you are using a KeyValue backend chained to a Simple backend.
class KeyValue class KeyValue
using I18n::HashRefinements
module Implementation module Implementation
attr_accessor :store attr_accessor :store

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'i18n/backend/base'
module I18n module I18n
module Backend module Backend
# A simple backend that reads translations from YAML files and stores them in # A simple backend that reads translations from YAML files and stores them in
@ -17,6 +19,8 @@ module I18n
# #
# I18n::Backend::Simple.include(I18n::Backend::Pluralization) # I18n::Backend::Simple.include(I18n::Backend::Pluralization)
class Simple class Simple
using I18n::HashRefinements
(class << self; self; end).class_eval { public :include } (class << self; self; end).class_eval { public :include }
module Implementation module Implementation
@ -39,7 +43,7 @@ module I18n
end end
locale = locale.to_sym locale = locale.to_sym
translations[locale] ||= {} translations[locale] ||= {}
data = data.deep_stringify_keys.deep_symbolize_keys data = data.deep_symbolize_keys
translations[locale].deep_merge!(data) translations[locale].deep_merge!(data)
end end
@ -84,8 +88,11 @@ module I18n
keys = I18n.normalize_keys(locale, key, scope, options[:separator]) keys = I18n.normalize_keys(locale, key, scope, options[:separator])
keys.inject(translations) do |result, _key| keys.inject(translations) do |result, _key|
_key = _key.to_sym return nil unless result.is_a?(Hash)
return nil unless result.is_a?(Hash) && result.has_key?(_key) unless result.has_key?(_key)
_key = _key.to_s.to_sym
return nil unless result.has_key?(_key)
end
result = result[_key] result = result[_key]
result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol) result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
result result

View File

@ -0,0 +1,37 @@
module I18n
module HashRefinements
refine Hash do
def slice(*keep_keys)
h = {}
keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
h
end
def except(*less_keys)
slice(*keys - less_keys)
end
def deep_symbolize_keys
each_with_object({}) do |(key, value), result|
value = value.deep_symbolize_keys if value.is_a?(Hash)
result[symbolize_key(key)] = value
result
end
end
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
def deep_merge!(data)
merger = lambda do |_key, v1, v2|
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
end
merge!(data, &merger)
end
private
def symbolize_key(key)
key.respond_to?(:to_sym) ? key.to_sym : key
end
end
end
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module I18n module I18n
VERSION = "1.2.0" VERSION = "1.3.0"
end end