activesupport 3.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +798 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +13 -7
- data/lib/active_support/array_inquirer.rb +44 -0
- data/lib/active_support/backtrace_cleaner.rb +38 -34
- data/lib/active_support/benchmarkable.rb +17 -28
- data/lib/active_support/cache/file_store.rb +85 -70
- data/lib/active_support/cache/mem_cache_store.rb +75 -66
- data/lib/active_support/cache/memory_store.rb +31 -23
- data/lib/active_support/cache/null_store.rb +41 -0
- data/lib/active_support/cache/strategy/local_cache.rb +73 -70
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +44 -0
- data/lib/active_support/cache.rb +360 -294
- data/lib/active_support/callbacks.rb +563 -393
- data/lib/active_support/concern.rb +42 -34
- data/lib/active_support/concurrency/latch.rb +19 -0
- data/lib/active_support/concurrency/share_lock.rb +186 -0
- data/lib/active_support/configurable.rb +70 -12
- data/lib/active_support/core_ext/array/access.rb +53 -9
- data/lib/active_support/core_ext/array/conversions.rb +109 -62
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +39 -32
- data/lib/active_support/core_ext/array/inquiry.rb +17 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -0
- data/lib/active_support/core_ext/array/wrap.rb +16 -18
- data/lib/active_support/core_ext/array.rb +2 -2
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -36
- data/lib/active_support/core_ext/class/attribute.rb +47 -34
- data/lib/active_support/core_ext/class/attribute_accessors.rb +4 -79
- data/lib/active_support/core_ext/class/subclasses.rb +12 -7
- data/lib/active_support/core_ext/class.rb +0 -3
- data/lib/active_support/core_ext/date/blank.rb +12 -0
- data/lib/active_support/core_ext/date/calculations.rb +57 -167
- data/lib/active_support/core_ext/date/conversions.rb +31 -42
- data/lib/active_support/core_ext/date/zones.rb +2 -10
- data/lib/active_support/core_ext/date.rb +5 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +335 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +1 -0
- data/lib/active_support/core_ext/date_time/blank.rb +12 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +132 -65
- data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +36 -34
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/digest/uuid.rb +51 -0
- data/lib/active_support/core_ext/enumerable.rb +81 -74
- data/lib/active_support/core_ext/file/atomic.rb +53 -26
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/hash/compact.rb +20 -0
- data/lib/active_support/core_ext/hash/conversions.rb +175 -70
- data/lib/active_support/core_ext/hash/deep_merge.rb +30 -8
- data/lib/active_support/core_ext/hash/except.rb +11 -12
- data/lib/active_support/core_ext/hash/indifferent_access.rb +7 -8
- data/lib/active_support/core_ext/hash/keys.rb +147 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +22 -14
- data/lib/active_support/core_ext/hash/transform_values.rb +29 -0
- data/lib/active_support/core_ext/hash.rb +2 -2
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/multiple.rb +4 -0
- data/lib/active_support/core_ext/integer/time.rb +12 -22
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -2
- data/lib/active_support/core_ext/kernel/concern.rb +12 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -15
- data/lib/active_support/core_ext/kernel/reporting.rb +12 -62
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/kernel.rb +2 -3
- data/lib/active_support/core_ext/load_error.rb +14 -7
- data/lib/active_support/core_ext/marshal.rb +22 -0
- data/lib/active_support/core_ext/module/aliasing.rb +16 -12
- data/lib/active_support/core_ext/module/anonymous.rb +12 -8
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
- data/lib/active_support/core_ext/module/attribute_accessors.rb +165 -13
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
- data/lib/active_support/core_ext/module/concerning.rb +135 -0
- data/lib/active_support/core_ext/module/delegation.rb +141 -68
- data/lib/active_support/core_ext/module/deprecation.rb +17 -3
- data/lib/active_support/core_ext/module/introspection.rb +9 -31
- data/lib/active_support/core_ext/module/method_transplanting.rb +3 -0
- data/lib/active_support/core_ext/module/qualified_const.rb +70 -0
- data/lib/active_support/core_ext/module/reachable.rb +1 -3
- data/lib/active_support/core_ext/module/remove_method.rb +24 -5
- data/lib/active_support/core_ext/module.rb +3 -3
- data/lib/active_support/core_ext/name_error.rb +15 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
- data/lib/active_support/core_ext/numeric/time.rb +31 -36
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +52 -18
- data/lib/active_support/core_ext/object/deep_dup.rb +53 -0
- data/lib/active_support/core_ext/object/duplicable.rb +12 -20
- data/lib/active_support/core_ext/object/inclusion.rb +13 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/json.rb +205 -0
- data/lib/active_support/core_ext/object/to_param.rb +1 -55
- data/lib/active_support/core_ext/object/to_query.rb +66 -9
- data/lib/active_support/core_ext/object/try.rb +124 -33
- data/lib/active_support/core_ext/object/with_options.rb +37 -11
- data/lib/active_support/core_ext/object.rb +2 -1
- data/lib/active_support/core_ext/range/conversions.rb +17 -7
- data/lib/active_support/core_ext/range/each.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +20 -18
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +1 -2
- data/lib/active_support/core_ext/securerandom.rb +23 -0
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/behavior.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +41 -38
- data/lib/active_support/core_ext/string/exclude.rb +6 -1
- data/lib/active_support/core_ext/string/filters.rb +70 -17
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +139 -59
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +46 -65
- data/lib/active_support/core_ext/string/output_safety.rb +153 -56
- data/lib/active_support/core_ext/string/strip.rb +3 -6
- data/lib/active_support/core_ext/string/zones.rb +14 -0
- data/lib/active_support/core_ext/string.rb +2 -3
- data/lib/active_support/core_ext/struct.rb +3 -0
- data/lib/active_support/core_ext/time/calculations.rb +173 -173
- data/lib/active_support/core_ext/time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/time/conversions.rb +33 -29
- data/lib/active_support/core_ext/time/marshal.rb +2 -56
- data/lib/active_support/core_ext/time/zones.rb +57 -32
- data/lib/active_support/core_ext/time.rb +5 -0
- data/lib/active_support/core_ext/uri.rb +13 -19
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/dependencies/interlock.rb +51 -0
- data/lib/active_support/dependencies.rb +315 -265
- data/lib/active_support/deprecation/behaviors.rb +71 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +59 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +82 -14
- data/lib/active_support/deprecation/reporting.rb +61 -14
- data/lib/active_support/deprecation.rb +38 -13
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration/iso8601_parser.rb +122 -0
- data/lib/active_support/duration/iso8601_serializer.rb +51 -0
- data/lib/active_support/duration.rb +85 -14
- data/lib/active_support/evented_file_update_checker.rb +194 -0
- data/lib/active_support/execution_wrapper.rb +117 -0
- data/lib/active_support/executor.rb +6 -0
- data/lib/active_support/file_update_checker.rb +138 -17
- data/lib/active_support/gem_version.rb +15 -0
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +199 -49
- data/lib/active_support/i18n.rb +6 -2
- data/lib/active_support/i18n_railtie.rb +40 -21
- data/lib/active_support/inflections.rb +22 -13
- data/lib/active_support/inflector/inflections.rb +175 -144
- data/lib/active_support/inflector/methods.rb +328 -91
- data/lib/active_support/inflector/transliterate.rb +51 -37
- data/lib/active_support/json/decoding.rb +31 -22
- data/lib/active_support/json/encoding.rb +88 -248
- data/lib/active_support/key_generator.rb +71 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -25
- data/lib/active_support/locale/en.yml +102 -3
- data/lib/active_support/log_subscriber/test_helper.rb +24 -21
- data/lib/active_support/log_subscriber.rb +36 -49
- data/lib/active_support/logger.rb +106 -0
- data/lib/active_support/logger_silence.rb +28 -0
- data/lib/active_support/logger_thread_safe_level.rb +31 -0
- data/lib/active_support/message_encryptor.rb +72 -36
- data/lib/active_support/message_verifier.rb +96 -24
- data/lib/active_support/multibyte/chars.rb +88 -333
- data/lib/active_support/multibyte/unicode.rb +156 -136
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/notifications/fanout.rb +115 -19
- data/lib/active_support/notifications/instrumenter.rb +52 -15
- data/lib/active_support/notifications.rb +168 -33
- data/lib/active_support/number_helper/number_converter.rb +182 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +44 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +28 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +62 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +12 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +92 -0
- data/lib/active_support/number_helper.rb +368 -0
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +18 -183
- data/lib/active_support/ordered_options.rb +44 -24
- data/lib/active_support/per_thread_registry.rb +58 -0
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +25 -34
- data/lib/active_support/reloader.rb +129 -0
- data/lib/active_support/rescuable.rb +98 -48
- data/lib/active_support/security_utils.rb +27 -0
- data/lib/active_support/string_inquirer.rb +14 -9
- data/lib/active_support/subscriber.rb +120 -0
- data/lib/active_support/tagged_logging.rb +78 -0
- data/lib/active_support/test_case.rb +69 -17
- data/lib/active_support/testing/assertions.rb +43 -41
- data/lib/active_support/testing/autorun.rb +12 -0
- data/lib/active_support/testing/constant_lookup.rb +50 -0
- data/lib/active_support/testing/declarative.rb +7 -21
- data/lib/active_support/testing/deprecation.rb +14 -33
- data/lib/active_support/testing/file_fixtures.rb +34 -0
- data/lib/active_support/testing/isolation.rb +53 -95
- data/lib/active_support/testing/method_call_assertions.rb +41 -0
- data/lib/active_support/testing/setup_and_teardown.rb +21 -82
- data/lib/active_support/testing/stream.rb +42 -0
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/testing/time_helpers.rb +134 -0
- data/lib/active_support/time.rb +6 -23
- data/lib/active_support/time_with_zone.rb +239 -92
- data/lib/active_support/values/time_zone.rb +236 -160
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +5 -7
- data/lib/active_support/xml_mini/jdom.rb +19 -13
- data/lib/active_support/xml_mini/libxml.rb +3 -4
- data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
- data/lib/active_support/xml_mini/nokogiri.rb +3 -4
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
- data/lib/active_support/xml_mini/rexml.rb +8 -10
- data/lib/active_support/xml_mini.rb +66 -34
- data/lib/active_support.rb +40 -23
- metadata +185 -134
- data/CHANGELOG +0 -1534
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/buffered_logger.rb +0 -137
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -178
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/zones.rb +0 -21
- 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 -11
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/kernel/requires.rb +0 -28
- data/lib/active_support/core_ext/logger.rb +0 -81
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -43
- data/lib/active_support/core_ext/object/to_json.rb +0 -19
- data/lib/active_support/core_ext/proc.rb +0 -14
- 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/encoding.rb +0 -11
- 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/file_watcher.rb +0 -36
- data/lib/active_support/json/variable.rb +0 -9
- data/lib/active_support/memoizable.rb +0 -105
- 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/secure_random.rb +0 -6
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/pending.rb +0 -52
- 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 -60
@@ -1,26 +1,25 @@
|
|
1
|
-
begin
|
2
|
-
require 'psych'
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
1
|
require 'yaml'
|
7
2
|
|
8
3
|
YAML.add_builtin_type("omap") do |type, val|
|
9
|
-
ActiveSupport::OrderedHash[val.map
|
4
|
+
ActiveSupport::OrderedHash[val.map{ |v| v.to_a.first }]
|
10
5
|
end
|
11
6
|
|
12
7
|
module ActiveSupport
|
13
|
-
#
|
14
|
-
# order
|
15
|
-
# implements a hash that preserves insertion order, as in Ruby 1.9:
|
8
|
+
# DEPRECATED: <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
|
9
|
+
# insertion order.
|
16
10
|
#
|
17
11
|
# oh = ActiveSupport::OrderedHash.new
|
18
12
|
# oh[:a] = 1
|
19
13
|
# oh[:b] = 2
|
20
14
|
# oh.keys # => [:a, :b], this order is guaranteed
|
21
15
|
#
|
22
|
-
#
|
23
|
-
|
16
|
+
# Also, maps the +omap+ feature for YAML files
|
17
|
+
# (See http://yaml.org/type/omap.html) to support ordered items
|
18
|
+
# when loading from yaml.
|
19
|
+
#
|
20
|
+
# <tt>ActiveSupport::OrderedHash</tt> is namespaced to prevent conflicts
|
21
|
+
# with other implementations.
|
22
|
+
class OrderedHash < ::Hash
|
24
23
|
def to_yaml_type
|
25
24
|
"!tag:yaml.org,2002:omap"
|
26
25
|
end
|
@@ -29,185 +28,21 @@ module ActiveSupport
|
|
29
28
|
coder.represent_seq '!omap', map { |k,v| { k => v } }
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
def select(*args, &block)
|
32
|
+
dup.tap { |hash| hash.select!(*args, &block) }
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
each do |k, v|
|
40
|
-
seq.add(k => v)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
35
|
+
def reject(*args, &block)
|
36
|
+
dup.tap { |hash| hash.reject!(*args, &block) }
|
44
37
|
end
|
45
38
|
|
46
39
|
def nested_under_indifferent_access
|
47
40
|
self
|
48
41
|
end
|
49
42
|
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
# In MRI the Hash class is core and written in C. In particular, methods are
|
54
|
-
# programmed with explicit C function calls and polymorphism is not honored.
|
55
|
-
#
|
56
|
-
# For example, []= is crucial in this implementation to maintain the @keys
|
57
|
-
# array but hash.c invokes rb_hash_aset() originally. This prevents method
|
58
|
-
# reuse through inheritance and forces us to reimplement stuff.
|
59
|
-
#
|
60
|
-
# For instance, we cannot use the inherited #merge! because albeit the algorithm
|
61
|
-
# itself would work, our []= is not being called at all by the C code.
|
62
|
-
|
63
|
-
def initialize(*args, &block)
|
64
|
-
super
|
65
|
-
@keys = []
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.[](*args)
|
69
|
-
ordered_hash = new
|
70
|
-
|
71
|
-
if (args.length == 1 && args.first.is_a?(Array))
|
72
|
-
args.first.each do |key_value_pair|
|
73
|
-
next unless (key_value_pair.is_a?(Array))
|
74
|
-
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
75
|
-
end
|
76
|
-
|
77
|
-
return ordered_hash
|
78
|
-
end
|
79
|
-
|
80
|
-
unless (args.size % 2 == 0)
|
81
|
-
raise ArgumentError.new("odd number of arguments for Hash")
|
82
|
-
end
|
83
|
-
|
84
|
-
args.each_with_index do |val, ind|
|
85
|
-
next if (ind % 2 != 0)
|
86
|
-
ordered_hash[val] = args[ind + 1]
|
87
|
-
end
|
88
|
-
|
89
|
-
ordered_hash
|
90
|
-
end
|
91
|
-
|
92
|
-
def initialize_copy(other)
|
93
|
-
super
|
94
|
-
# make a deep copy of keys
|
95
|
-
@keys = other.keys
|
96
|
-
end
|
97
|
-
|
98
|
-
def []=(key, value)
|
99
|
-
@keys << key unless has_key?(key)
|
100
|
-
super
|
101
|
-
end
|
102
|
-
|
103
|
-
def delete(key)
|
104
|
-
if has_key? key
|
105
|
-
index = @keys.index(key)
|
106
|
-
@keys.delete_at index
|
107
|
-
end
|
108
|
-
super
|
109
|
-
end
|
110
|
-
|
111
|
-
def delete_if
|
112
|
-
super
|
113
|
-
sync_keys!
|
114
|
-
self
|
115
|
-
end
|
116
|
-
|
117
|
-
def reject!
|
118
|
-
super
|
119
|
-
sync_keys!
|
120
|
-
self
|
121
|
-
end
|
122
|
-
|
123
|
-
def reject(&block)
|
124
|
-
dup.reject!(&block)
|
125
|
-
end
|
126
|
-
|
127
|
-
def keys
|
128
|
-
@keys.dup
|
129
|
-
end
|
130
|
-
|
131
|
-
def values
|
132
|
-
@keys.collect { |key| self[key] }
|
133
|
-
end
|
134
|
-
|
135
|
-
def to_hash
|
136
|
-
self
|
137
|
-
end
|
138
|
-
|
139
|
-
def to_a
|
140
|
-
@keys.map { |key| [ key, self[key] ] }
|
141
|
-
end
|
142
|
-
|
143
|
-
def each_key
|
144
|
-
return to_enum(:each_key) unless block_given?
|
145
|
-
@keys.each { |key| yield key }
|
146
|
-
self
|
147
|
-
end
|
148
|
-
|
149
|
-
def each_value
|
150
|
-
return to_enum(:each_value) unless block_given?
|
151
|
-
@keys.each { |key| yield self[key]}
|
152
|
-
self
|
153
|
-
end
|
154
|
-
|
155
|
-
def each
|
156
|
-
return to_enum(:each) unless block_given?
|
157
|
-
@keys.each {|key| yield [key, self[key]]}
|
158
|
-
self
|
159
|
-
end
|
160
|
-
|
161
|
-
alias_method :each_pair, :each
|
162
|
-
|
163
|
-
alias_method :select, :find_all
|
164
|
-
|
165
|
-
def clear
|
166
|
-
super
|
167
|
-
@keys.clear
|
168
|
-
self
|
169
|
-
end
|
170
|
-
|
171
|
-
def shift
|
172
|
-
k = @keys.first
|
173
|
-
v = delete(k)
|
174
|
-
[k, v]
|
175
|
-
end
|
176
|
-
|
177
|
-
def merge!(other_hash)
|
178
|
-
if block_given?
|
179
|
-
other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
|
180
|
-
else
|
181
|
-
other_hash.each { |k, v| self[k] = v }
|
182
|
-
end
|
183
|
-
self
|
184
|
-
end
|
185
|
-
|
186
|
-
alias_method :update, :merge!
|
187
|
-
|
188
|
-
def merge(other_hash, &block)
|
189
|
-
dup.merge!(other_hash, &block)
|
190
|
-
end
|
191
|
-
|
192
|
-
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
|
193
|
-
def replace(other)
|
194
|
-
super
|
195
|
-
@keys = other.keys
|
196
|
-
self
|
197
|
-
end
|
198
|
-
|
199
|
-
def invert
|
200
|
-
OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
|
201
|
-
end
|
202
|
-
|
203
|
-
def inspect
|
204
|
-
"#<OrderedHash #{super}>"
|
205
|
-
end
|
206
|
-
|
207
|
-
private
|
208
|
-
def sync_keys!
|
209
|
-
@keys.delete_if {|k| !has_key?(k)}
|
210
|
-
end
|
43
|
+
# Returns true to make sure that this hash is extractable via <tt>Array#extract_options!</tt>
|
44
|
+
def extractable_options?
|
45
|
+
true
|
211
46
|
end
|
212
47
|
end
|
213
48
|
end
|
@@ -1,23 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# h =
|
6
|
-
# h[:
|
7
|
-
# h[:
|
8
|
-
# h[:
|
9
|
-
# h[:
|
10
|
-
#
|
11
|
-
# Using
|
12
|
-
#
|
13
|
-
# h = ActiveSupport::OrderedOptions.new
|
14
|
-
# h.boy = 'John'
|
15
|
-
# h.girl = 'Mary'
|
16
|
-
# h.boy # => 'John'
|
17
|
-
# h.girl # => 'Mary'
|
18
|
-
#
|
19
|
-
|
20
|
-
|
1
|
+
module ActiveSupport
|
2
|
+
# Usually key value pairs are handled something like this:
|
3
|
+
#
|
4
|
+
# h = {}
|
5
|
+
# h[:boy] = 'John'
|
6
|
+
# h[:girl] = 'Mary'
|
7
|
+
# h[:boy] # => 'John'
|
8
|
+
# h[:girl] # => 'Mary'
|
9
|
+
# h[:dog] # => nil
|
10
|
+
#
|
11
|
+
# Using +OrderedOptions+, the above code could be reduced to:
|
12
|
+
#
|
13
|
+
# h = ActiveSupport::OrderedOptions.new
|
14
|
+
# h.boy = 'John'
|
15
|
+
# h.girl = 'Mary'
|
16
|
+
# h.boy # => 'John'
|
17
|
+
# h.girl # => 'Mary'
|
18
|
+
# h.dog # => nil
|
19
|
+
#
|
20
|
+
# To raise an exception when the value is blank, append a
|
21
|
+
# bang to the key name, like:
|
22
|
+
#
|
23
|
+
# h.dog! # => raises KeyError: key not found: :dog
|
24
|
+
#
|
25
|
+
class OrderedOptions < Hash
|
21
26
|
alias_method :_get, :[] # preserve the original #[] method
|
22
27
|
protected :_get # make it protected
|
23
28
|
|
@@ -30,18 +35,33 @@ module ActiveSupport #:nodoc:
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def method_missing(name, *args)
|
33
|
-
|
34
|
-
|
38
|
+
name_string = name.to_s
|
39
|
+
if name_string.chomp!('=')
|
40
|
+
self[name_string] = args.first
|
35
41
|
else
|
36
|
-
|
42
|
+
bangs = name_string.chomp!('!')
|
43
|
+
|
44
|
+
if bangs
|
45
|
+
fetch(name_string.to_sym).presence || raise(KeyError.new("#{name_string} is blank."))
|
46
|
+
else
|
47
|
+
self[name_string]
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
40
|
-
def
|
52
|
+
def respond_to_missing?(name, include_private)
|
41
53
|
true
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
57
|
+
# +InheritableOptions+ provides a constructor to build an +OrderedOptions+
|
58
|
+
# hash inherited from another hash.
|
59
|
+
#
|
60
|
+
# Use this if you already have some hash and you want to create a new one based on it.
|
61
|
+
#
|
62
|
+
# h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
|
63
|
+
# h.girl # => 'Mary'
|
64
|
+
# h.boy # => 'John'
|
45
65
|
class InheritableOptions < OrderedOptions
|
46
66
|
def initialize(parent = nil)
|
47
67
|
if parent.kind_of?(OrderedOptions)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# NOTE: This approach has been deprecated for end-user code in favor of thread_mattr_accessor and friends.
|
5
|
+
# Please use that approach instead.
|
6
|
+
#
|
7
|
+
# This module is used to encapsulate access to thread local variables.
|
8
|
+
#
|
9
|
+
# Instead of polluting the thread locals namespace:
|
10
|
+
#
|
11
|
+
# Thread.current[:connection_handler]
|
12
|
+
#
|
13
|
+
# you define a class that extends this module:
|
14
|
+
#
|
15
|
+
# module ActiveRecord
|
16
|
+
# class RuntimeRegistry
|
17
|
+
# extend ActiveSupport::PerThreadRegistry
|
18
|
+
#
|
19
|
+
# attr_accessor :connection_handler
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# and invoke the declared instance accessors as class methods. So
|
24
|
+
#
|
25
|
+
# ActiveRecord::RuntimeRegistry.connection_handler = connection_handler
|
26
|
+
#
|
27
|
+
# sets a connection handler local to the current thread, and
|
28
|
+
#
|
29
|
+
# ActiveRecord::RuntimeRegistry.connection_handler
|
30
|
+
#
|
31
|
+
# returns a connection handler local to the current thread.
|
32
|
+
#
|
33
|
+
# This feature is accomplished by instantiating the class and storing the
|
34
|
+
# instance as a thread local keyed by the class name. In the example above
|
35
|
+
# a key "ActiveRecord::RuntimeRegistry" is stored in <tt>Thread.current</tt>.
|
36
|
+
# The class methods proxy to said thread local instance.
|
37
|
+
#
|
38
|
+
# If the class has an initializer, it must accept no arguments.
|
39
|
+
module PerThreadRegistry
|
40
|
+
def self.extended(object)
|
41
|
+
object.instance_variable_set '@per_thread_registry_key', object.name.freeze
|
42
|
+
end
|
43
|
+
|
44
|
+
def instance
|
45
|
+
Thread.current[@per_thread_registry_key] ||= new
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
def method_missing(name, *args, &block) # :nodoc:
|
50
|
+
# Caches the method definition as a singleton method of the receiver.
|
51
|
+
#
|
52
|
+
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
|
53
|
+
singleton_class.delegate name, to: :instance
|
54
|
+
|
55
|
+
send(name, *args, &block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
# A class with no predefined methods that behaves similarly to Builder's
|
3
|
+
# BlankSlate. Used for proxy classes.
|
4
|
+
class ProxyObject < ::BasicObject
|
5
|
+
undef_method :==
|
6
|
+
undef_method :equal?
|
7
|
+
|
8
|
+
# Let ActiveSupport::ProxyObject at least raise exceptions.
|
9
|
+
def raise(*args)
|
10
|
+
::Object.send(:raise, *args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# This is private interface.
|
2
|
+
#
|
3
|
+
# Rails components cherry pick from Active Support as needed, but there are a
|
4
|
+
# few features that are used for sure in some way or another and it is not worth
|
5
|
+
# putting individual requires absolutely everywhere. Think blank? for example.
|
6
|
+
#
|
7
|
+
# This file is loaded by every Rails component except Active Support itself,
|
8
|
+
# but it does not belong to the Rails public interface. It is internal to
|
9
|
+
# Rails and can change anytime.
|
10
|
+
|
11
|
+
# Defines Object#blank? and Object#present?.
|
12
|
+
require 'active_support/core_ext/object/blank'
|
13
|
+
|
14
|
+
# Rails own autoload, eager_load, etc.
|
15
|
+
require 'active_support/dependencies/autoload'
|
16
|
+
|
17
|
+
# Support for ClassMethods and the included macro.
|
18
|
+
require 'active_support/concern'
|
19
|
+
|
20
|
+
# Defines Class#class_attribute.
|
21
|
+
require 'active_support/core_ext/class/attribute'
|
22
|
+
|
23
|
+
# Defines Module#delegate.
|
24
|
+
require 'active_support/core_ext/module/delegation'
|
25
|
+
|
26
|
+
# Defines ActiveSupport::Deprecation.
|
27
|
+
require 'active_support/deprecation'
|
@@ -1,60 +1,51 @@
|
|
1
1
|
require "active_support"
|
2
|
-
require "rails"
|
3
2
|
require "active_support/i18n_railtie"
|
4
3
|
|
5
4
|
module ActiveSupport
|
6
|
-
class Railtie < Rails::Railtie
|
5
|
+
class Railtie < Rails::Railtie # :nodoc:
|
7
6
|
config.active_support = ActiveSupport::OrderedOptions.new
|
8
7
|
|
9
|
-
|
10
|
-
# on +nil+ values) if Configuration#whiny_nils is true.
|
11
|
-
initializer "active_support.initialize_whiny_nils" do |app|
|
12
|
-
require 'active_support/whiny_nil' if app.config.whiny_nils
|
13
|
-
end
|
8
|
+
config.eager_load_namespaces << ActiveSupport
|
14
9
|
|
15
10
|
initializer "active_support.deprecation_behavior" do |app|
|
16
11
|
if deprecation = app.config.active_support.deprecation
|
17
12
|
ActiveSupport::Deprecation.behavior = deprecation
|
18
|
-
else
|
19
|
-
defaults = {"development" => :log,
|
20
|
-
"production" => :notify,
|
21
|
-
"test" => :stderr}
|
22
|
-
|
23
|
-
env = Rails.env
|
24
|
-
|
25
|
-
if defaults.key?(env)
|
26
|
-
msg = "You did not specify how you would like Rails to report " \
|
27
|
-
"deprecation notices for your #{env} environment, please " \
|
28
|
-
"set config.active_support.deprecation to :#{defaults[env]} " \
|
29
|
-
"at config/environments/#{env}.rb"
|
30
|
-
|
31
|
-
warn msg
|
32
|
-
ActiveSupport::Deprecation.behavior = defaults[env]
|
33
|
-
else
|
34
|
-
msg = "You did not specify how you would like Rails to report " \
|
35
|
-
"deprecation notices for your #{env} environment, please " \
|
36
|
-
"set config.active_support.deprecation to :log, :notify or " \
|
37
|
-
":stderr at config/environments/#{env}.rb"
|
38
|
-
|
39
|
-
warn msg
|
40
|
-
ActiveSupport::Deprecation.behavior = :stderr
|
41
|
-
end
|
42
13
|
end
|
43
14
|
end
|
44
15
|
|
45
16
|
# Sets the default value for Time.zone
|
46
17
|
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
47
18
|
initializer "active_support.initialize_time_zone" do |app|
|
19
|
+
begin
|
20
|
+
TZInfo::DataSource.get
|
21
|
+
rescue TZInfo::DataSourceNotFound => e
|
22
|
+
raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
|
23
|
+
end
|
48
24
|
require 'active_support/core_ext/time/zones'
|
49
25
|
zone_default = Time.find_zone!(app.config.time_zone)
|
50
26
|
|
51
27
|
unless zone_default
|
52
|
-
raise \
|
53
|
-
'
|
54
|
-
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
|
28
|
+
raise 'Value assigned to config.time_zone not recognized. ' \
|
29
|
+
'Run "rake time:zones:all" for a time zone names list.'
|
55
30
|
end
|
56
31
|
|
57
32
|
Time.zone_default = zone_default
|
58
33
|
end
|
34
|
+
|
35
|
+
# Sets the default week start
|
36
|
+
# If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
|
37
|
+
initializer "active_support.initialize_beginning_of_week" do |app|
|
38
|
+
require 'active_support/core_ext/date/calculations'
|
39
|
+
beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
|
40
|
+
|
41
|
+
Date.beginning_of_week_default = beginning_of_week_default
|
42
|
+
end
|
43
|
+
|
44
|
+
initializer "active_support.set_configs" do |app|
|
45
|
+
app.config.active_support.each do |k, v|
|
46
|
+
k = "#{k}="
|
47
|
+
ActiveSupport.send(k, v) if ActiveSupport.respond_to? k
|
48
|
+
end
|
49
|
+
end
|
59
50
|
end
|
60
51
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'active_support/execution_wrapper'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
#--
|
5
|
+
# This class defines several callbacks:
|
6
|
+
#
|
7
|
+
# to_prepare -- Run once at application startup, and also from
|
8
|
+
# +to_run+.
|
9
|
+
#
|
10
|
+
# to_run -- Run before a work run that is reloading. If
|
11
|
+
# +reload_classes_only_on_change+ is true (the default), the class
|
12
|
+
# unload will have already occurred.
|
13
|
+
#
|
14
|
+
# to_complete -- Run after a work run that has reloaded. If
|
15
|
+
# +reload_classes_only_on_change+ is false, the class unload will
|
16
|
+
# have occurred after the work run, but before this callback.
|
17
|
+
#
|
18
|
+
# before_class_unload -- Run immediately before the classes are
|
19
|
+
# unloaded.
|
20
|
+
#
|
21
|
+
# after_class_unload -- Run immediately after the classes are
|
22
|
+
# unloaded.
|
23
|
+
#
|
24
|
+
class Reloader < ExecutionWrapper
|
25
|
+
define_callbacks :prepare
|
26
|
+
|
27
|
+
define_callbacks :class_unload
|
28
|
+
|
29
|
+
def self.to_prepare(*args, &block)
|
30
|
+
set_callback(:prepare, *args, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.before_class_unload(*args, &block)
|
34
|
+
set_callback(:class_unload, *args, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.after_class_unload(*args, &block)
|
38
|
+
set_callback(:class_unload, :after, *args, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
to_run(:after) { self.class.prepare! }
|
42
|
+
|
43
|
+
# Initiate a manual reload
|
44
|
+
def self.reload!
|
45
|
+
executor.wrap do
|
46
|
+
new.tap do |instance|
|
47
|
+
begin
|
48
|
+
instance.run!
|
49
|
+
ensure
|
50
|
+
instance.complete!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
prepare!
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.run! # :nodoc:
|
58
|
+
if check!
|
59
|
+
super
|
60
|
+
else
|
61
|
+
Null
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Run the supplied block as a work unit, reloading code as needed
|
66
|
+
def self.wrap
|
67
|
+
executor.wrap do
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class_attribute :executor
|
73
|
+
class_attribute :check
|
74
|
+
|
75
|
+
self.executor = Executor
|
76
|
+
self.check = lambda { false }
|
77
|
+
|
78
|
+
def self.check! # :nodoc:
|
79
|
+
@should_reload ||= check.call
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.reloaded! # :nodoc:
|
83
|
+
@should_reload = false
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.prepare! # :nodoc:
|
87
|
+
new.run_callbacks(:prepare)
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize
|
91
|
+
super
|
92
|
+
@locked = false
|
93
|
+
end
|
94
|
+
|
95
|
+
# Acquire the ActiveSupport::Dependencies::Interlock unload lock,
|
96
|
+
# ensuring it will be released automatically
|
97
|
+
def require_unload_lock!
|
98
|
+
unless @locked
|
99
|
+
ActiveSupport::Dependencies.interlock.start_unloading
|
100
|
+
@locked = true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Release the unload lock if it has been previously obtained
|
105
|
+
def release_unload_lock!
|
106
|
+
if @locked
|
107
|
+
@locked = false
|
108
|
+
ActiveSupport::Dependencies.interlock.done_unloading
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def run! # :nodoc:
|
113
|
+
super
|
114
|
+
release_unload_lock!
|
115
|
+
end
|
116
|
+
|
117
|
+
def class_unload!(&block) # :nodoc:
|
118
|
+
require_unload_lock!
|
119
|
+
run_callbacks(:class_unload, &block)
|
120
|
+
end
|
121
|
+
|
122
|
+
def complete! # :nodoc:
|
123
|
+
super
|
124
|
+
self.class.reloaded!
|
125
|
+
ensure
|
126
|
+
release_unload_lock!
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|