activesupport 3.2.22.5 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +364 -135
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -4
- data/lib/active_support/backtrace_cleaner.rb +33 -25
- data/lib/active_support/basic_object.rb +7 -17
- data/lib/active_support/benchmarkable.rb +19 -15
- data/lib/active_support/buffered_logger.rb +9 -113
- data/lib/active_support/cache/file_store.rb +14 -14
- data/lib/active_support/cache/mem_cache_store.rb +24 -30
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/cache/strategy/local_cache.rb +48 -37
- data/lib/active_support/cache.rb +228 -183
- data/lib/active_support/callbacks.rb +201 -253
- data/lib/active_support/concern.rb +16 -23
- data/lib/active_support/concurrency/latch.rb +27 -0
- data/lib/active_support/configurable.rb +69 -12
- data/lib/active_support/core_ext/array/access.rb +17 -9
- data/lib/active_support/core_ext/array/conversions.rb +115 -55
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +21 -22
- data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
- data/lib/active_support/core_ext/array/wrap.rb +13 -16
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -24
- data/lib/active_support/core_ext/class/attribute.rb +40 -32
- data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
- data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
- data/lib/active_support/core_ext/class/subclasses.rb +11 -5
- data/lib/active_support/core_ext/date/calculations.rb +44 -187
- data/lib/active_support/core_ext/date/conversions.rb +16 -38
- data/lib/active_support/core_ext/date/zones.rb +25 -2
- data/lib/active_support/core_ext/date.rb +5 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +77 -62
- data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
- data/lib/active_support/core_ext/date_time/zones.rb +11 -8
- data/lib/active_support/core_ext/date_time.rb +4 -0
- data/lib/active_support/core_ext/enumerable.rb +26 -73
- data/lib/active_support/core_ext/file/atomic.rb +27 -11
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/hash/conversions.rb +145 -79
- data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
- data/lib/active_support/core_ext/hash/diff.rb +5 -4
- data/lib/active_support/core_ext/hash/except.rb +1 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
- data/lib/active_support/core_ext/hash/keys.rb +108 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +12 -12
- data/lib/active_support/core_ext/hash.rb +0 -1
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/time.rb +17 -12
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
- data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/load_error.rb +7 -5
- data/lib/active_support/core_ext/logger.rb +7 -23
- data/lib/active_support/core_ext/marshal.rb +21 -0
- data/lib/active_support/core_ext/module/aliasing.rb +8 -9
- data/lib/active_support/core_ext/module/anonymous.rb +2 -7
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
- data/lib/active_support/core_ext/module/delegation.rb +92 -49
- data/lib/active_support/core_ext/module/deprecation.rb +19 -3
- data/lib/active_support/core_ext/module/introspection.rb +17 -27
- data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
- data/lib/active_support/core_ext/module/remove_method.rb +1 -5
- data/lib/active_support/core_ext/module.rb +1 -3
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
- data/lib/active_support/core_ext/numeric/time.rb +6 -6
- data/lib/active_support/core_ext/numeric.rb +1 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +7 -23
- data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
- data/lib/active_support/core_ext/object/duplicable.rb +1 -30
- data/lib/active_support/core_ext/object/inclusion.rb +8 -7
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/to_json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +5 -2
- data/lib/active_support/core_ext/object/try.rb +46 -25
- data/lib/active_support/core_ext/object/with_options.rb +7 -8
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/proc.rb +3 -0
- data/lib/active_support/core_ext/range/conversions.rb +0 -2
- data/lib/active_support/core_ext/range/include_range.rb +3 -1
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +0 -2
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/conversions.rb +27 -38
- data/lib/active_support/core_ext/string/encoding.rb +6 -9
- data/lib/active_support/core_ext/string/filters.rb +24 -18
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +70 -60
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +41 -64
- data/lib/active_support/core_ext/string/output_safety.rb +59 -51
- data/lib/active_support/core_ext/string/zones.rb +13 -0
- data/lib/active_support/core_ext/string.rb +2 -3
- data/lib/active_support/core_ext/struct.rb +6 -0
- data/lib/active_support/core_ext/thread.rb +74 -0
- data/lib/active_support/core_ext/time/calculations.rb +108 -184
- data/lib/active_support/core_ext/time/conversions.rb +27 -51
- data/lib/active_support/core_ext/time/marshal.rb +0 -27
- data/lib/active_support/core_ext/time/zones.rb +27 -17
- data/lib/active_support/core_ext/time.rb +5 -0
- data/lib/active_support/core_ext/uri.rb +13 -17
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/dependencies.rb +160 -141
- data/lib/active_support/deprecation/behaviors.rb +44 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +33 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
- data/lib/active_support/deprecation/reporting.rb +40 -11
- data/lib/active_support/deprecation.rb +39 -14
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration.rb +6 -8
- data/lib/active_support/file_update_checker.rb +63 -47
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +127 -42
- data/lib/active_support/i18n.rb +4 -0
- data/lib/active_support/i18n_railtie.rb +5 -22
- data/lib/active_support/inflections.rb +14 -12
- data/lib/active_support/inflector/inflections.rb +108 -71
- data/lib/active_support/inflector/methods.rb +181 -160
- data/lib/active_support/inflector/transliterate.rb +16 -17
- data/lib/active_support/json/decoding.rb +18 -17
- data/lib/active_support/json/encoding.rb +93 -39
- data/lib/active_support/json/variable.rb +10 -1
- data/lib/active_support/key_generator.rb +75 -0
- data/lib/active_support/lazy_load_hooks.rb +21 -19
- data/lib/active_support/locale/en.yml +100 -3
- data/lib/active_support/log_subscriber/test_helper.rb +18 -15
- data/lib/active_support/log_subscriber.rb +35 -52
- data/lib/active_support/logger.rb +57 -0
- data/lib/active_support/logger_silence.rb +24 -0
- data/lib/active_support/message_encryptor.rb +38 -35
- data/lib/active_support/message_verifier.rb +9 -15
- data/lib/active_support/multibyte/chars.rb +80 -333
- data/lib/active_support/multibyte/unicode.rb +74 -64
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/notifications/fanout.rb +112 -18
- data/lib/active_support/notifications/instrumenter.rb +33 -14
- data/lib/active_support/notifications.rb +79 -26
- data/lib/active_support/number_helper.rb +637 -0
- data/lib/active_support/ordered_hash.rb +8 -190
- data/lib/active_support/ordered_options.rb +21 -23
- data/lib/active_support/per_thread_registry.rb +52 -0
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +12 -32
- data/lib/active_support/rescuable.rb +9 -4
- data/lib/active_support/string_inquirer.rb +13 -8
- data/lib/active_support/subscriber.rb +93 -0
- data/lib/active_support/tagged_logging.rb +51 -73
- data/lib/active_support/test_case.rb +46 -17
- data/lib/active_support/testing/assertions.rb +56 -26
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +54 -0
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +0 -19
- data/lib/active_support/testing/isolation.rb +29 -58
- data/lib/active_support/testing/pending.rb +5 -43
- data/lib/active_support/testing/setup_and_teardown.rb +6 -92
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/time.rb +6 -21
- data/lib/active_support/time_with_zone.rb +80 -43
- data/lib/active_support/values/time_zone.rb +81 -60
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +7 -6
- data/lib/active_support/xml_mini/jdom.rb +9 -11
- data/lib/active_support/xml_mini/libxml.rb +1 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
- data/lib/active_support/xml_mini/nokogiri.rb +1 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
- data/lib/active_support/xml_mini/rexml.rb +6 -8
- data/lib/active_support/xml_mini.rb +35 -17
- data/lib/active_support.rb +8 -21
- metadata +104 -72
- data/lib/active_support/base64.rb +0 -54
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/date/freeze.rb +0 -33
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
- data/lib/active_support/core_ext/io.rb +0 -15
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -45
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/cover.rb +0 -3
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/memoizable.rb +0 -116
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/security_utils.rb +0 -27
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/performance/jruby.rb +0 -115
- data/lib/active_support/testing/performance/rubinius.rb +0 -113
- data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
- data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
- data/lib/active_support/testing/performance/ruby.rb +0 -152
- data/lib/active_support/testing/performance.rb +0 -317
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -24
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require 'active_support/core_ext/module/aliasing'
|
|
2
|
-
|
|
3
|
-
class Range
|
|
4
|
-
begin
|
|
5
|
-
(1..2).step
|
|
6
|
-
# Range#step doesn't return an Enumerator
|
|
7
|
-
rescue LocalJumpError
|
|
8
|
-
# Return an array when step is called without a block.
|
|
9
|
-
def step_with_blockless(*args, &block)
|
|
10
|
-
if block_given?
|
|
11
|
-
step_without_blockless(*args, &block)
|
|
12
|
-
else
|
|
13
|
-
array = []
|
|
14
|
-
step_without_blockless(*args) { |step| array << step }
|
|
15
|
-
array
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
else
|
|
19
|
-
def step_with_blockless(*args, &block) #:nodoc:
|
|
20
|
-
if block_given?
|
|
21
|
-
step_without_blockless(*args, &block)
|
|
22
|
-
else
|
|
23
|
-
step_without_blockless(*args).to_a
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
alias_method_chain :step, :blockless
|
|
29
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'active_support/core_ext/kernel/reporting'
|
|
2
|
-
|
|
3
|
-
# Fixes the rexml vulnerability disclosed at:
|
|
4
|
-
# http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
|
|
5
|
-
# This fix is identical to rexml-expansion-fix version 1.0.1.
|
|
6
|
-
#
|
|
7
|
-
# We still need to distribute this fix because albeit the REXML
|
|
8
|
-
# in recent 1.8.7s is patched, it wasn't in early patchlevels.
|
|
9
|
-
require 'rexml/rexml'
|
|
10
|
-
|
|
11
|
-
# Earlier versions of rexml defined REXML::Version, newer ones REXML::VERSION
|
|
12
|
-
unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2"
|
|
13
|
-
silence_warnings { require 'rexml/document' }
|
|
14
|
-
|
|
15
|
-
# REXML in 1.8.7 has the patch but early patchlevels didn't update Version from 3.1.7.2.
|
|
16
|
-
unless REXML::Document.respond_to?(:entity_expansion_limit=)
|
|
17
|
-
silence_warnings { require 'rexml/entity' }
|
|
18
|
-
|
|
19
|
-
module REXML #:nodoc:
|
|
20
|
-
class Entity < Child #:nodoc:
|
|
21
|
-
undef_method :unnormalized
|
|
22
|
-
def unnormalized
|
|
23
|
-
document.record_entity_expansion! if document
|
|
24
|
-
v = value()
|
|
25
|
-
return nil if v.nil?
|
|
26
|
-
@unnormalized = Text::unnormalize(v, parent)
|
|
27
|
-
@unnormalized
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
class Document < Element #:nodoc:
|
|
31
|
-
@@entity_expansion_limit = 10_000
|
|
32
|
-
def self.entity_expansion_limit= val
|
|
33
|
-
@@entity_expansion_limit = val
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def record_entity_expansion!
|
|
37
|
-
@number_of_expansions ||= 0
|
|
38
|
-
@number_of_expansions += 1
|
|
39
|
-
if @number_of_expansions > @@entity_expansion_limit
|
|
40
|
-
raise "Number of entity expansions exceeded, processing aborted."
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
# See http://fast-xs.rubyforge.org/ by Eric Wong.
|
|
3
|
-
# Also included with hpricot.
|
|
4
|
-
require 'fast_xs'
|
|
5
|
-
rescue LoadError
|
|
6
|
-
# fast_xs extension unavailable
|
|
7
|
-
else
|
|
8
|
-
begin
|
|
9
|
-
require 'builder'
|
|
10
|
-
rescue LoadError
|
|
11
|
-
# builder demands the first shot at defining String#to_xs
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class String
|
|
15
|
-
alias_method :original_xs, :to_xs if method_defined?(:to_xs)
|
|
16
|
-
alias_method :to_xs, :fast_xs
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require 'date'
|
|
2
|
-
|
|
3
|
-
class Time
|
|
4
|
-
# Ruby 1.8-cvs and early 1.9 series define private Time#to_date
|
|
5
|
-
%w(to_date to_datetime).each do |method|
|
|
6
|
-
if private_instance_methods.include?(method) || private_instance_methods.include?(method.to_sym)
|
|
7
|
-
public method
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
require 'active_support/core_ext/kernel/singleton_class'
|
|
2
|
-
require 'active_support/core_ext/module/aliasing'
|
|
3
|
-
require 'active_support/deprecation'
|
|
4
|
-
|
|
5
|
-
module ActiveSupport
|
|
6
|
-
module Memoizable
|
|
7
|
-
def self.extended(base)
|
|
8
|
-
ActiveSupport::Deprecation.warn "ActiveSupport::Memoizable is deprecated and will be removed in future releases," \
|
|
9
|
-
"simply use Ruby memoization pattern instead.", caller
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.memoized_ivar_for(symbol)
|
|
14
|
-
"@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
module InstanceMethods
|
|
18
|
-
def self.included(base)
|
|
19
|
-
base.class_eval do
|
|
20
|
-
unless base.method_defined?(:freeze_without_memoizable)
|
|
21
|
-
alias_method_chain :freeze, :memoizable
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def freeze_with_memoizable
|
|
27
|
-
memoize_all unless frozen?
|
|
28
|
-
freeze_without_memoizable
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def memoize_all
|
|
32
|
-
prime_cache ".*"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def unmemoize_all
|
|
36
|
-
flush_cache ".*"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def prime_cache(*syms)
|
|
40
|
-
syms.each do |sym|
|
|
41
|
-
methods.each do |m|
|
|
42
|
-
if m.to_s =~ /^_unmemoized_(#{sym})/
|
|
43
|
-
if method(m).arity == 0
|
|
44
|
-
__send__($1)
|
|
45
|
-
else
|
|
46
|
-
ivar = ActiveSupport::Memoizable.memoized_ivar_for($1)
|
|
47
|
-
instance_variable_set(ivar, {})
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def flush_cache(*syms)
|
|
55
|
-
syms.each do |sym|
|
|
56
|
-
(methods + private_methods + protected_methods).each do |m|
|
|
57
|
-
if m.to_s =~ /^_unmemoized_(#{sym.to_s.gsub(/\?\Z/, '\?')})/
|
|
58
|
-
ivar = ActiveSupport::Memoizable.memoized_ivar_for($1)
|
|
59
|
-
instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def memoize(*symbols)
|
|
67
|
-
symbols.each do |symbol|
|
|
68
|
-
original_method = :"_unmemoized_#{symbol}"
|
|
69
|
-
memoized_ivar = ActiveSupport::Memoizable.memoized_ivar_for(symbol)
|
|
70
|
-
|
|
71
|
-
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
|
72
|
-
include InstanceMethods # include InstanceMethods
|
|
73
|
-
#
|
|
74
|
-
if method_defined?(:#{original_method}) # if method_defined?(:_unmemoized_mime_type)
|
|
75
|
-
raise "Already memoized #{symbol}" # raise "Already memoized mime_type"
|
|
76
|
-
end # end
|
|
77
|
-
alias #{original_method} #{symbol} # alias _unmemoized_mime_type mime_type
|
|
78
|
-
#
|
|
79
|
-
if instance_method(:#{symbol}).arity == 0 # if instance_method(:mime_type).arity == 0
|
|
80
|
-
def #{symbol}(reload = false) # def mime_type(reload = false)
|
|
81
|
-
if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty? # if reload || !defined?(@_memoized_mime_type) || @_memoized_mime_type.empty?
|
|
82
|
-
#{memoized_ivar} = [#{original_method}] # @_memoized_mime_type = [_unmemoized_mime_type]
|
|
83
|
-
end # end
|
|
84
|
-
#{memoized_ivar}[0] # @_memoized_mime_type[0]
|
|
85
|
-
end # end
|
|
86
|
-
else # else
|
|
87
|
-
def #{symbol}(*args) # def mime_type(*args)
|
|
88
|
-
#{memoized_ivar} ||= {} unless frozen? # @_memoized_mime_type ||= {} unless frozen?
|
|
89
|
-
args_length = method(:#{original_method}).arity # args_length = method(:_unmemoized_mime_type).arity
|
|
90
|
-
if args.length == args_length + 1 && # if args.length == args_length + 1 &&
|
|
91
|
-
(args.last == true || args.last == :reload) # (args.last == true || args.last == :reload)
|
|
92
|
-
reload = args.pop # reload = args.pop
|
|
93
|
-
end # end
|
|
94
|
-
#
|
|
95
|
-
if defined?(#{memoized_ivar}) && #{memoized_ivar} # if defined?(@_memoized_mime_type) && @_memoized_mime_type
|
|
96
|
-
if !reload && #{memoized_ivar}.has_key?(args) # if !reload && @_memoized_mime_type.has_key?(args)
|
|
97
|
-
#{memoized_ivar}[args] # @_memoized_mime_type[args]
|
|
98
|
-
elsif #{memoized_ivar} # elsif @_memoized_mime_type
|
|
99
|
-
#{memoized_ivar}[args] = #{original_method}(*args) # @_memoized_mime_type[args] = _unmemoized_mime_type(*args)
|
|
100
|
-
end # end
|
|
101
|
-
else # else
|
|
102
|
-
#{original_method}(*args) # _unmemoized_mime_type(*args)
|
|
103
|
-
end # end
|
|
104
|
-
end # end
|
|
105
|
-
end # end
|
|
106
|
-
#
|
|
107
|
-
if private_method_defined?(#{original_method.inspect}) # if private_method_defined?(:_unmemoized_mime_type)
|
|
108
|
-
private #{symbol.inspect} # private :mime_type
|
|
109
|
-
elsif protected_method_defined?(#{original_method.inspect}) # elsif protected_method_defined?(:_unmemoized_mime_type)
|
|
110
|
-
protected #{symbol.inspect} # protected :mime_type
|
|
111
|
-
end # end
|
|
112
|
-
EOS
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module ActiveSupport #:nodoc:
|
|
4
|
-
module Multibyte #:nodoc:
|
|
5
|
-
if Kernel.const_defined?(:Encoding)
|
|
6
|
-
# Returns a regular expression that matches valid characters in the current encoding
|
|
7
|
-
def self.valid_character
|
|
8
|
-
VALID_CHARACTER[Encoding.default_external.to_s]
|
|
9
|
-
end
|
|
10
|
-
else
|
|
11
|
-
def self.valid_character
|
|
12
|
-
case $KCODE
|
|
13
|
-
when 'UTF8'
|
|
14
|
-
VALID_CHARACTER['UTF-8']
|
|
15
|
-
when 'SJIS'
|
|
16
|
-
VALID_CHARACTER['Shift_JIS']
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
if 'string'.respond_to?(:valid_encoding?)
|
|
22
|
-
# Verifies the encoding of a string
|
|
23
|
-
def self.verify(string)
|
|
24
|
-
string.valid_encoding?
|
|
25
|
-
end
|
|
26
|
-
else
|
|
27
|
-
def self.verify(string)
|
|
28
|
-
if expression = valid_character
|
|
29
|
-
# Splits the string on character boundaries, which are determined based on $KCODE.
|
|
30
|
-
string.split(//).all? { |c| expression =~ c }
|
|
31
|
-
else
|
|
32
|
-
true
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Verifies the encoding of the string and raises an exception when it's not valid
|
|
38
|
-
def self.verify!(string)
|
|
39
|
-
raise EncodingError.new("Found characters with invalid encoding") unless verify(string)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
if 'string'.respond_to?(:force_encoding)
|
|
43
|
-
# Removes all invalid characters from the string.
|
|
44
|
-
#
|
|
45
|
-
# Note: this method is a no-op in Ruby 1.9
|
|
46
|
-
def self.clean(string)
|
|
47
|
-
string
|
|
48
|
-
end
|
|
49
|
-
else
|
|
50
|
-
def self.clean(string)
|
|
51
|
-
if expression = valid_character
|
|
52
|
-
# Splits the string on character boundaries, which are determined based on $KCODE.
|
|
53
|
-
string.split(//).grep(expression).join
|
|
54
|
-
else
|
|
55
|
-
string
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Backported Ruby builtins so you can code with the latest & greatest
|
|
2
|
-
# but still run on any Ruby 1.8.x.
|
|
3
|
-
#
|
|
4
|
-
# Date next_year, next_month
|
|
5
|
-
# DateTime to_date, to_datetime, xmlschema
|
|
6
|
-
# Enumerable group_by, each_with_object, none?
|
|
7
|
-
# Process Process.daemon
|
|
8
|
-
# REXML security fix
|
|
9
|
-
# String ord
|
|
10
|
-
# Time to_date, to_time, to_datetime
|
|
11
|
-
require 'active_support'
|
|
12
|
-
require 'active_support/core_ext/date/calculations'
|
|
13
|
-
require 'active_support/core_ext/date_time/conversions'
|
|
14
|
-
require 'active_support/core_ext/enumerable'
|
|
15
|
-
require 'active_support/core_ext/process/daemon'
|
|
16
|
-
require 'active_support/core_ext/string/conversions'
|
|
17
|
-
require 'active_support/core_ext/string/interpolation'
|
|
18
|
-
require 'active_support/core_ext/string/encoding'
|
|
19
|
-
require 'active_support/core_ext/rexml'
|
|
20
|
-
require 'active_support/core_ext/time/conversions'
|
|
21
|
-
require 'active_support/core_ext/file/path'
|
|
22
|
-
require 'active_support/core_ext/module/method_names'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'digest'
|
|
2
|
-
|
|
3
|
-
module ActiveSupport
|
|
4
|
-
module SecurityUtils
|
|
5
|
-
# Constant time string comparison.
|
|
6
|
-
#
|
|
7
|
-
# The values compared should be of fixed length, such as strings
|
|
8
|
-
# that have already been processed by HMAC. This should not be used
|
|
9
|
-
# on variable length plaintext strings because it could leak length info
|
|
10
|
-
# via timing attacks.
|
|
11
|
-
def secure_compare(a, b)
|
|
12
|
-
return false unless a.bytesize == b.bytesize
|
|
13
|
-
|
|
14
|
-
l = a.unpack "C#{a.bytesize}"
|
|
15
|
-
|
|
16
|
-
res = 0
|
|
17
|
-
b.each_byte { |byte| res |= byte ^ l.shift }
|
|
18
|
-
res == 0
|
|
19
|
-
end
|
|
20
|
-
module_function :secure_compare
|
|
21
|
-
|
|
22
|
-
def variable_size_secure_compare(a, b) # :nodoc:
|
|
23
|
-
secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))
|
|
24
|
-
end
|
|
25
|
-
module_function :variable_size_secure_compare
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
require 'jruby/profiler'
|
|
2
|
-
require 'java'
|
|
3
|
-
java_import java.lang.management.ManagementFactory
|
|
4
|
-
|
|
5
|
-
module ActiveSupport
|
|
6
|
-
module Testing
|
|
7
|
-
module Performance
|
|
8
|
-
DEFAULTS.merge!(
|
|
9
|
-
if ENV["BENCHMARK_TESTS"]
|
|
10
|
-
{:metrics => [:wall_time, :user_time, :memory, :gc_runs, :gc_time]}
|
|
11
|
-
else
|
|
12
|
-
{ :metrics => [:wall_time],
|
|
13
|
-
:formats => [:flat, :graph] }
|
|
14
|
-
end).freeze
|
|
15
|
-
|
|
16
|
-
protected
|
|
17
|
-
def run_gc
|
|
18
|
-
ManagementFactory.memory_mx_bean.gc
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class Profiler < Performer
|
|
22
|
-
def initialize(*args)
|
|
23
|
-
super
|
|
24
|
-
@supported = @metric.is_a?(Metrics::WallTime)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def run
|
|
28
|
-
return unless @supported
|
|
29
|
-
|
|
30
|
-
@total = time_with_block do
|
|
31
|
-
@data = JRuby::Profiler.profile do
|
|
32
|
-
full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def record
|
|
38
|
-
return unless @supported
|
|
39
|
-
|
|
40
|
-
klasses = full_profile_options[:formats].map { |f| JRuby::Profiler.const_get("#{f.to_s.camelize}ProfilePrinter") }.compact
|
|
41
|
-
|
|
42
|
-
klasses.each do |klass|
|
|
43
|
-
fname = output_filename(klass)
|
|
44
|
-
FileUtils.mkdir_p(File.dirname(fname))
|
|
45
|
-
file = File.open(fname, 'wb') do |file|
|
|
46
|
-
klass.new(@data).printProfile(file)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
protected
|
|
52
|
-
def output_filename(printer_class)
|
|
53
|
-
suffix =
|
|
54
|
-
case printer_class.name.demodulize
|
|
55
|
-
when 'FlatProfilePrinter'; 'flat.txt'
|
|
56
|
-
when 'GraphProfilePrinter'; 'graph.txt'
|
|
57
|
-
else printer_class.name.sub(/ProfilePrinter$/, '').underscore
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
"#{super()}_#{suffix}"
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
module Metrics
|
|
65
|
-
class Base
|
|
66
|
-
def profile
|
|
67
|
-
yield
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
protected
|
|
71
|
-
def with_gc_stats
|
|
72
|
-
ManagementFactory.memory_mx_bean.gc
|
|
73
|
-
yield
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
class WallTime < Time
|
|
78
|
-
def measure
|
|
79
|
-
super
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
class CpuTime < Time
|
|
84
|
-
def measure
|
|
85
|
-
ManagementFactory.thread_mx_bean.get_current_thread_cpu_time / 1000 / 1000 / 1000.0 # seconds
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
class UserTime < Time
|
|
90
|
-
def measure
|
|
91
|
-
ManagementFactory.thread_mx_bean.get_current_thread_user_time / 1000 / 1000 / 1000.0 # seconds
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
class Memory < DigitalInformationUnit
|
|
96
|
-
def measure
|
|
97
|
-
ManagementFactory.memory_mx_bean.non_heap_memory_usage.used + ManagementFactory.memory_mx_bean.heap_memory_usage.used
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
class GcRuns < Amount
|
|
102
|
-
def measure
|
|
103
|
-
ManagementFactory.garbage_collector_mx_beans.inject(0) { |total_runs, current_gc| total_runs += current_gc.collection_count }
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
class GcTime < Time
|
|
108
|
-
def measure
|
|
109
|
-
ManagementFactory.garbage_collector_mx_beans.inject(0) { |total_time, current_gc| total_time += current_gc.collection_time } / 1000.0 # seconds
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
require 'rubinius/agent'
|
|
2
|
-
|
|
3
|
-
module ActiveSupport
|
|
4
|
-
module Testing
|
|
5
|
-
module Performance
|
|
6
|
-
DEFAULTS.merge!(
|
|
7
|
-
if ENV["BENCHMARK_TESTS"]
|
|
8
|
-
{:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]}
|
|
9
|
-
else
|
|
10
|
-
{ :metrics => [:wall_time],
|
|
11
|
-
:formats => [:flat, :graph] }
|
|
12
|
-
end).freeze
|
|
13
|
-
|
|
14
|
-
protected
|
|
15
|
-
def run_gc
|
|
16
|
-
GC.run(true)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class Performer; end
|
|
20
|
-
|
|
21
|
-
class Profiler < Performer
|
|
22
|
-
def initialize(*args)
|
|
23
|
-
super
|
|
24
|
-
@supported = @metric.is_a?(Metrics::WallTime)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def run
|
|
28
|
-
return unless @supported
|
|
29
|
-
|
|
30
|
-
@profiler = Rubinius::Profiler::Instrumenter.new
|
|
31
|
-
|
|
32
|
-
@total = time_with_block do
|
|
33
|
-
@profiler.profile(false) do
|
|
34
|
-
full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def record
|
|
40
|
-
return unless @supported
|
|
41
|
-
|
|
42
|
-
if(full_profile_options[:formats].include?(:flat))
|
|
43
|
-
create_path_and_open_file(:flat) do |file|
|
|
44
|
-
@profiler.show(file)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
if(full_profile_options[:formats].include?(:graph))
|
|
49
|
-
create_path_and_open_file(:graph) do |file|
|
|
50
|
-
@profiler.show(file)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
protected
|
|
56
|
-
def create_path_and_open_file(printer_name)
|
|
57
|
-
fname = "#{output_filename}_#{printer_name}.txt"
|
|
58
|
-
FileUtils.mkdir_p(File.dirname(fname))
|
|
59
|
-
File.open(fname, 'wb') do |file|
|
|
60
|
-
yield(file)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
module Metrics
|
|
66
|
-
class Base
|
|
67
|
-
attr_reader :loopback
|
|
68
|
-
|
|
69
|
-
def profile
|
|
70
|
-
yield
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
protected
|
|
74
|
-
def with_gc_stats
|
|
75
|
-
@loopback = Rubinius::Agent.loopback
|
|
76
|
-
GC.run(true)
|
|
77
|
-
yield
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
class WallTime < Time
|
|
82
|
-
def measure
|
|
83
|
-
super
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
class Memory < DigitalInformationUnit
|
|
88
|
-
def measure
|
|
89
|
-
loopback.get("system.memory.counter.bytes").last
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
class Objects < Amount
|
|
94
|
-
def measure
|
|
95
|
-
loopback.get("system.memory.counter.objects").last
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
class GcRuns < Amount
|
|
100
|
-
def measure
|
|
101
|
-
loopback.get("system.gc.full.count").last + loopback.get("system.gc.young.count").last
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class GcTime < Time
|
|
106
|
-
def measure
|
|
107
|
-
(loopback.get("system.gc.full.wallclock").last + loopback.get("system.gc.young.wallclock").last) / 1000.0
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
module ActiveSupport
|
|
2
|
-
module Testing
|
|
3
|
-
module Performance
|
|
4
|
-
module Metrics
|
|
5
|
-
class Base
|
|
6
|
-
protected
|
|
7
|
-
# Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
|
|
8
|
-
if GC.respond_to?(:enable_stats)
|
|
9
|
-
def with_gc_stats
|
|
10
|
-
GC.enable_stats
|
|
11
|
-
GC.start
|
|
12
|
-
yield
|
|
13
|
-
ensure
|
|
14
|
-
GC.disable_stats
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class Memory < DigitalInformationUnit
|
|
20
|
-
# Ruby 1.8 + ruby-prof wrapper
|
|
21
|
-
if RubyProf.respond_to?(:measure_memory)
|
|
22
|
-
def measure
|
|
23
|
-
RubyProf.measure_memory
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
class Objects < Amount
|
|
29
|
-
# Ruby 1.8 + ruby-prof wrapper
|
|
30
|
-
if RubyProf.respond_to?(:measure_allocations)
|
|
31
|
-
def measure
|
|
32
|
-
RubyProf.measure_allocations
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
class GcRuns < Amount
|
|
38
|
-
# Ruby 1.8 + ruby-prof wrapper
|
|
39
|
-
if RubyProf.respond_to?(:measure_gc_runs)
|
|
40
|
-
def measure
|
|
41
|
-
RubyProf.measure_gc_runs
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class GcTime < Time
|
|
47
|
-
# Ruby 1.8 + ruby-prof wrapper
|
|
48
|
-
if RubyProf.respond_to?(:measure_gc_time)
|
|
49
|
-
def measure
|
|
50
|
-
RubyProf.measure_gc_time / 1000.0 / 1000.0
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|