activesupport 3.2.22.5 → 4.0.0.beta1
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 +4 -4
- data/CHANGELOG.md +325 -136
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -2
- data/lib/active_support.rb +8 -21
- 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.rb +203 -171
- data/lib/active_support/cache/file_store.rb +12 -12
- 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/callbacks.rb +195 -247
- 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.rb +1 -0
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/array/access.rb +17 -9
- data/lib/active_support/core_ext/array/conversions.rb +113 -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 +11 -14
- data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
- data/lib/active_support/core_ext/class/attribute.rb +12 -8
- 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.rb +6 -0
- data/lib/active_support/core_ext/date/calculations.rb +34 -188
- data/lib/active_support/core_ext/date/conversions.rb +16 -38
- data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date/zones.rb +25 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
- data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
- data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date_time/zones.rb +11 -8
- data/lib/active_support/core_ext/enumerable.rb +26 -73
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/file/atomic.rb +27 -11
- data/lib/active_support/core_ext/hash.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/infinite_comparable.rb +35 -0
- 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 +19 -0
- data/lib/active_support/core_ext/module.rb +1 -3
- 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 +57 -40
- 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/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
- data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
- data/lib/active_support/core_ext/numeric/time.rb +6 -6
- data/lib/active_support/core_ext/object.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 +6 -6
- 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/proc.rb +3 -0
- data/lib/active_support/core_ext/range.rb +0 -2
- data/lib/active_support/core_ext/range/conversions.rb +0 -2
- data/lib/active_support/core_ext/range/include_range.rb +1 -1
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/string.rb +2 -2
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/conversions.rb +29 -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/struct.rb +6 -0
- data/lib/active_support/core_ext/thread.rb +74 -0
- data/lib/active_support/core_ext/time.rb +6 -0
- data/lib/active_support/core_ext/time/calculations.rb +105 -193
- data/lib/active_support/core_ext/time/conversions.rb +27 -51
- data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
- 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/uri.rb +13 -17
- data/lib/active_support/dependencies.rb +160 -141
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/deprecation.rb +39 -14
- 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/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 +112 -37
- 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.rb +56 -36
- data/lib/active_support/log_subscriber/test_helper.rb +18 -15
- data/lib/active_support/logger.rb +57 -0
- data/lib/active_support/logger_silence.rb +24 -0
- data/lib/active_support/message_encryptor.rb +32 -29
- data/lib/active_support/message_verifier.rb +8 -14
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/multibyte/chars.rb +80 -333
- data/lib/active_support/multibyte/unicode.rb +74 -64
- data/lib/active_support/notifications.rb +57 -25
- data/lib/active_support/notifications/fanout.rb +105 -18
- data/lib/active_support/notifications/instrumenter.rb +32 -13
- data/lib/active_support/number_helper.rb +636 -0
- data/lib/active_support/ordered_hash.rb +8 -190
- data/lib/active_support/ordered_options.rb +21 -23
- 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/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 +52 -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 +25 -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 +78 -43
- data/lib/active_support/values/time_zone.rb +77 -58
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +4 -4
- data/lib/active_support/xml_mini.rb +35 -17
- data/lib/active_support/xml_mini/jdom.rb +9 -17
- data/lib/active_support/xml_mini/libxml.rb +1 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
- data/lib/active_support/xml_mini/nokogiri.rb +1 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
- data/lib/active_support/xml_mini/rexml.rb +6 -8
- metadata +107 -77
- 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.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- 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.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- 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/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.rb +0 -317
- 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.rb +0 -152
- 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/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -24
@@ -1,8 +1,3 @@
|
|
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|
|
@@ -10,16 +5,20 @@ YAML.add_builtin_type("omap") do |type, val|
|
|
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
|
+
# <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
|
-
#
|
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.
|
23
22
|
class OrderedHash < ::Hash
|
24
23
|
def to_yaml_type
|
25
24
|
"!tag:yaml.org,2002:omap"
|
@@ -29,20 +28,6 @@ module ActiveSupport
|
|
29
28
|
coder.represent_seq '!omap', map { |k,v| { k => v } }
|
30
29
|
end
|
31
30
|
|
32
|
-
def to_yaml(opts = {})
|
33
|
-
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
|
34
|
-
return super
|
35
|
-
end
|
36
|
-
|
37
|
-
YAML.quick_emit(self, opts) do |out|
|
38
|
-
out.seq(taguri) do |seq|
|
39
|
-
each do |k, v|
|
40
|
-
seq.add(k => v)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
31
|
def nested_under_indifferent_access
|
47
32
|
self
|
48
33
|
end
|
@@ -51,172 +36,5 @@ module ActiveSupport
|
|
51
36
|
def extractable_options?
|
52
37
|
true
|
53
38
|
end
|
54
|
-
|
55
|
-
# Hash is ordered in Ruby 1.9!
|
56
|
-
if RUBY_VERSION < '1.9'
|
57
|
-
|
58
|
-
# In MRI the Hash class is core and written in C. In particular, methods are
|
59
|
-
# programmed with explicit C function calls and polymorphism is not honored.
|
60
|
-
#
|
61
|
-
# For example, []= is crucial in this implementation to maintain the @keys
|
62
|
-
# array but hash.c invokes rb_hash_aset() originally. This prevents method
|
63
|
-
# reuse through inheritance and forces us to reimplement stuff.
|
64
|
-
#
|
65
|
-
# For instance, we cannot use the inherited #merge! because albeit the algorithm
|
66
|
-
# itself would work, our []= is not being called at all by the C code.
|
67
|
-
|
68
|
-
def initialize(*args, &block)
|
69
|
-
super
|
70
|
-
@keys = []
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.[](*args)
|
74
|
-
ordered_hash = new
|
75
|
-
|
76
|
-
if (args.length == 1 && args.first.is_a?(Array))
|
77
|
-
args.first.each do |key_value_pair|
|
78
|
-
next unless (key_value_pair.is_a?(Array))
|
79
|
-
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
80
|
-
end
|
81
|
-
|
82
|
-
return ordered_hash
|
83
|
-
end
|
84
|
-
|
85
|
-
unless (args.size % 2 == 0)
|
86
|
-
raise ArgumentError.new("odd number of arguments for Hash")
|
87
|
-
end
|
88
|
-
|
89
|
-
args.each_with_index do |val, ind|
|
90
|
-
next if (ind % 2 != 0)
|
91
|
-
ordered_hash[val] = args[ind + 1]
|
92
|
-
end
|
93
|
-
|
94
|
-
ordered_hash
|
95
|
-
end
|
96
|
-
|
97
|
-
def initialize_copy(other)
|
98
|
-
super
|
99
|
-
# make a deep copy of keys
|
100
|
-
@keys = other.keys
|
101
|
-
end
|
102
|
-
|
103
|
-
def []=(key, value)
|
104
|
-
@keys << key unless has_key?(key)
|
105
|
-
super
|
106
|
-
end
|
107
|
-
|
108
|
-
def delete(key)
|
109
|
-
if has_key? key
|
110
|
-
index = @keys.index(key)
|
111
|
-
@keys.delete_at index
|
112
|
-
end
|
113
|
-
super
|
114
|
-
end
|
115
|
-
|
116
|
-
def delete_if
|
117
|
-
super
|
118
|
-
sync_keys!
|
119
|
-
self
|
120
|
-
end
|
121
|
-
|
122
|
-
def reject!
|
123
|
-
super
|
124
|
-
sync_keys!
|
125
|
-
self
|
126
|
-
end
|
127
|
-
|
128
|
-
def reject(&block)
|
129
|
-
dup.reject!(&block)
|
130
|
-
end
|
131
|
-
|
132
|
-
def keys
|
133
|
-
@keys.dup
|
134
|
-
end
|
135
|
-
|
136
|
-
def values
|
137
|
-
@keys.collect { |key| self[key] }
|
138
|
-
end
|
139
|
-
|
140
|
-
def to_hash
|
141
|
-
self
|
142
|
-
end
|
143
|
-
|
144
|
-
def to_a
|
145
|
-
@keys.map { |key| [ key, self[key] ] }
|
146
|
-
end
|
147
|
-
|
148
|
-
def each_key
|
149
|
-
return to_enum(:each_key) unless block_given?
|
150
|
-
@keys.each { |key| yield key }
|
151
|
-
self
|
152
|
-
end
|
153
|
-
|
154
|
-
def each_value
|
155
|
-
return to_enum(:each_value) unless block_given?
|
156
|
-
@keys.each { |key| yield self[key]}
|
157
|
-
self
|
158
|
-
end
|
159
|
-
|
160
|
-
def each
|
161
|
-
return to_enum(:each) unless block_given?
|
162
|
-
@keys.each {|key| yield [key, self[key]]}
|
163
|
-
self
|
164
|
-
end
|
165
|
-
|
166
|
-
def each_pair
|
167
|
-
return to_enum(:each_pair) unless block_given?
|
168
|
-
@keys.each {|key| yield key, self[key]}
|
169
|
-
self
|
170
|
-
end
|
171
|
-
|
172
|
-
alias_method :select, :find_all
|
173
|
-
|
174
|
-
def clear
|
175
|
-
super
|
176
|
-
@keys.clear
|
177
|
-
self
|
178
|
-
end
|
179
|
-
|
180
|
-
def shift
|
181
|
-
k = @keys.first
|
182
|
-
v = delete(k)
|
183
|
-
[k, v]
|
184
|
-
end
|
185
|
-
|
186
|
-
def merge!(other_hash)
|
187
|
-
if block_given?
|
188
|
-
other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
|
189
|
-
else
|
190
|
-
other_hash.each { |k, v| self[k] = v }
|
191
|
-
end
|
192
|
-
self
|
193
|
-
end
|
194
|
-
|
195
|
-
alias_method :update, :merge!
|
196
|
-
|
197
|
-
def merge(other_hash, &block)
|
198
|
-
dup.merge!(other_hash, &block)
|
199
|
-
end
|
200
|
-
|
201
|
-
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
|
202
|
-
def replace(other)
|
203
|
-
super
|
204
|
-
@keys = other.keys
|
205
|
-
self
|
206
|
-
end
|
207
|
-
|
208
|
-
def invert
|
209
|
-
OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
|
210
|
-
end
|
211
|
-
|
212
|
-
def inspect
|
213
|
-
"#<OrderedHash #{super}>"
|
214
|
-
end
|
215
|
-
|
216
|
-
private
|
217
|
-
def sync_keys!
|
218
|
-
@keys.delete_if {|k| !has_key?(k)}
|
219
|
-
end
|
220
|
-
end
|
221
39
|
end
|
222
40
|
end
|
@@ -1,23 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# h =
|
6
|
-
# h[:
|
7
|
-
# h[:
|
8
|
-
# h[:
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# h =
|
14
|
-
# h.
|
15
|
-
# h.
|
16
|
-
# h.
|
17
|
-
|
18
|
-
#
|
19
|
-
module ActiveSupport #:nodoc:
|
20
|
-
class OrderedOptions < OrderedHash
|
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
|
+
#
|
10
|
+
# Using +OrderedOptions+, the above code could be reduced to:
|
11
|
+
#
|
12
|
+
# h = ActiveSupport::OrderedOptions.new
|
13
|
+
# h.boy = 'John'
|
14
|
+
# h.girl = 'Mary'
|
15
|
+
# h.boy # => 'John'
|
16
|
+
# h.girl # => 'Mary'
|
17
|
+
class OrderedOptions < Hash
|
21
18
|
alias_method :_get, :[] # preserve the original #[] method
|
22
19
|
protected :_get # make it protected
|
23
20
|
|
@@ -30,14 +27,15 @@ module ActiveSupport #:nodoc:
|
|
30
27
|
end
|
31
28
|
|
32
29
|
def method_missing(name, *args)
|
33
|
-
|
34
|
-
|
30
|
+
name_string = name.to_s
|
31
|
+
if name_string.chomp!('=')
|
32
|
+
self[name_string] = args.first
|
35
33
|
else
|
36
34
|
self[name]
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
def
|
38
|
+
def respond_to_missing?(name, include_private)
|
41
39
|
true
|
42
40
|
end
|
43
41
|
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 some way or another and it is not worth
|
5
|
+
# to put 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'
|
@@ -2,42 +2,14 @@ require "active_support"
|
|
2
2
|
require "active_support/i18n_railtie"
|
3
3
|
|
4
4
|
module ActiveSupport
|
5
|
-
class Railtie < Rails::Railtie
|
5
|
+
class Railtie < Rails::Railtie # :nodoc:
|
6
6
|
config.active_support = ActiveSupport::OrderedOptions.new
|
7
7
|
|
8
|
-
|
9
|
-
# on +nil+ values) if Configuration#whiny_nils is true.
|
10
|
-
initializer "active_support.initialize_whiny_nils" do |app|
|
11
|
-
require 'active_support/whiny_nil' if app.config.whiny_nils
|
12
|
-
end
|
8
|
+
config.eager_load_namespaces << ActiveSupport
|
13
9
|
|
14
10
|
initializer "active_support.deprecation_behavior" do |app|
|
15
11
|
if deprecation = app.config.active_support.deprecation
|
16
12
|
ActiveSupport::Deprecation.behavior = deprecation
|
17
|
-
else
|
18
|
-
defaults = {"development" => :log,
|
19
|
-
"production" => :notify,
|
20
|
-
"test" => :stderr}
|
21
|
-
|
22
|
-
env = Rails.env
|
23
|
-
|
24
|
-
if defaults.key?(env)
|
25
|
-
msg = "You did not specify how you would like Rails to report " \
|
26
|
-
"deprecation notices for your #{env} environment, please " \
|
27
|
-
"set config.active_support.deprecation to :#{defaults[env]} " \
|
28
|
-
"at config/environments/#{env}.rb"
|
29
|
-
|
30
|
-
warn msg
|
31
|
-
ActiveSupport::Deprecation.behavior = defaults[env]
|
32
|
-
else
|
33
|
-
msg = "You did not specify how you would like Rails to report " \
|
34
|
-
"deprecation notices for your #{env} environment, please " \
|
35
|
-
"set config.active_support.deprecation to :log, :notify or " \
|
36
|
-
":stderr at config/environments/#{env}.rb"
|
37
|
-
|
38
|
-
warn msg
|
39
|
-
ActiveSupport::Deprecation.behavior = :stderr
|
40
|
-
end
|
41
13
|
end
|
42
14
|
end
|
43
15
|
|
@@ -48,14 +20,22 @@ module ActiveSupport
|
|
48
20
|
zone_default = Time.find_zone!(app.config.time_zone)
|
49
21
|
|
50
22
|
unless zone_default
|
51
|
-
raise \
|
52
|
-
'Value assigned to config.time_zone not recognized.' +
|
23
|
+
raise 'Value assigned to config.time_zone not recognized. ' \
|
53
24
|
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
|
54
25
|
end
|
55
26
|
|
56
27
|
Time.zone_default = zone_default
|
57
28
|
end
|
58
29
|
|
30
|
+
# Sets the default week start
|
31
|
+
# If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
|
32
|
+
initializer "active_support.initialize_beginning_of_week" do |app|
|
33
|
+
require 'active_support/core_ext/date/calculations'
|
34
|
+
beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
|
35
|
+
|
36
|
+
Date.beginning_of_week_default = beginning_of_week_default
|
37
|
+
end
|
38
|
+
|
59
39
|
initializer "active_support.set_configs" do |app|
|
60
40
|
app.config.active_support.each do |k, v|
|
61
41
|
k = "#{k}="
|
@@ -31,11 +31,11 @@ module ActiveSupport
|
|
31
31
|
# any.
|
32
32
|
#
|
33
33
|
# class ApplicationController < ActionController::Base
|
34
|
-
# rescue_from User::NotAuthorized, :
|
35
|
-
# rescue_from ActiveRecord::RecordInvalid, :
|
34
|
+
# rescue_from User::NotAuthorized, with: :deny_access # self defined exception
|
35
|
+
# rescue_from ActiveRecord::RecordInvalid, with: :show_errors
|
36
36
|
#
|
37
37
|
# rescue_from 'MyAppError::Base' do |exception|
|
38
|
-
# render :
|
38
|
+
# render xml: exception, status: 500
|
39
39
|
# end
|
40
40
|
#
|
41
41
|
# protected
|
@@ -48,6 +48,7 @@ module ActiveSupport
|
|
48
48
|
# end
|
49
49
|
# end
|
50
50
|
#
|
51
|
+
# Exceptions raised inside exception handlers are not propagated up.
|
51
52
|
def rescue_from(*klasses, &block)
|
52
53
|
options = klasses.extract_options!
|
53
54
|
|
@@ -108,7 +109,11 @@ module ActiveSupport
|
|
108
109
|
when Symbol
|
109
110
|
method(rescuer)
|
110
111
|
when Proc
|
111
|
-
rescuer.
|
112
|
+
if rescuer.arity == 0
|
113
|
+
Proc.new { instance_exec(&rescuer) }
|
114
|
+
else
|
115
|
+
Proc.new { |_exception| instance_exec(_exception, &rescuer) }
|
116
|
+
end
|
112
117
|
end
|
113
118
|
end
|
114
119
|
end
|
@@ -3,19 +3,24 @@ module ActiveSupport
|
|
3
3
|
# for equality. The value returned by <tt>Rails.env</tt> is wrapped
|
4
4
|
# in a StringInquirer object so instead of calling this:
|
5
5
|
#
|
6
|
-
# Rails.env ==
|
6
|
+
# Rails.env == 'production'
|
7
7
|
#
|
8
8
|
# you can call this:
|
9
9
|
#
|
10
10
|
# Rails.env.production?
|
11
|
-
#
|
12
11
|
class StringInquirer < String
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
private
|
13
|
+
|
14
|
+
def respond_to_missing?(method_name, include_private = false)
|
15
|
+
method_name[-1] == '?'
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(method_name, *arguments)
|
19
|
+
if method_name[-1] == '?'
|
20
|
+
self == method_name[0..-2]
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
18
24
|
end
|
19
|
-
end
|
20
25
|
end
|
21
26
|
end
|