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,81 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
2
|
-
|
3
|
-
# Adds the 'around_level' method to Logger.
|
4
|
-
class Logger #:nodoc:
|
5
|
-
def self.define_around_helper(level)
|
6
|
-
module_eval <<-end_eval, __FILE__, __LINE__ + 1
|
7
|
-
def around_#{level}(before_message, after_message) # def around_debug(before_message, after_message, &block)
|
8
|
-
self.#{level}(before_message) # self.debug(before_message)
|
9
|
-
return_value = yield(self) # return_value = yield(self)
|
10
|
-
self.#{level}(after_message) # self.debug(after_message)
|
11
|
-
return_value # return_value
|
12
|
-
end # end
|
13
|
-
end_eval
|
14
|
-
end
|
15
|
-
[:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'logger'
|
19
|
-
|
20
|
-
# Extensions to the built-in Ruby logger.
|
21
|
-
#
|
22
|
-
# If you want to use the default log formatter as defined in the Ruby core, then you
|
23
|
-
# will need to set the formatter for the logger as in:
|
24
|
-
#
|
25
|
-
# logger.formatter = Formatter.new
|
26
|
-
#
|
27
|
-
# You can then specify the datetime format, for example:
|
28
|
-
#
|
29
|
-
# logger.datetime_format = "%Y-%m-%d"
|
30
|
-
#
|
31
|
-
# Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger
|
32
|
-
class Logger
|
33
|
-
##
|
34
|
-
# :singleton-method:
|
35
|
-
# Set to false to disable the silencer
|
36
|
-
cattr_accessor :silencer
|
37
|
-
self.silencer = true
|
38
|
-
|
39
|
-
# Silences the logger for the duration of the block.
|
40
|
-
def silence(temporary_level = Logger::ERROR)
|
41
|
-
if silencer
|
42
|
-
begin
|
43
|
-
old_logger_level, self.level = level, temporary_level
|
44
|
-
yield self
|
45
|
-
ensure
|
46
|
-
self.level = old_logger_level
|
47
|
-
end
|
48
|
-
else
|
49
|
-
yield self
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
alias :old_datetime_format= :datetime_format=
|
54
|
-
# Logging date-time format (string passed to +strftime+). Ignored if the formatter
|
55
|
-
# does not respond to datetime_format=.
|
56
|
-
def datetime_format=(datetime_format)
|
57
|
-
formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=)
|
58
|
-
end
|
59
|
-
|
60
|
-
alias :old_datetime_format :datetime_format
|
61
|
-
# Get the logging datetime format. Returns nil if the formatter does not support
|
62
|
-
# datetime formatting.
|
63
|
-
def datetime_format
|
64
|
-
formatter.datetime_format if formatter.respond_to?(:datetime_format)
|
65
|
-
end
|
66
|
-
|
67
|
-
alias :old_initialize :initialize
|
68
|
-
# Overwrite initialize to set a default formatter.
|
69
|
-
def initialize(*args)
|
70
|
-
old_initialize(*args)
|
71
|
-
self.formatter = SimpleFormatter.new
|
72
|
-
end
|
73
|
-
|
74
|
-
# Simple formatter which only displays the message.
|
75
|
-
class SimpleFormatter < Logger::Formatter
|
76
|
-
# This method is invoked when a log event occurs
|
77
|
-
def call(severity, timestamp, progname, msg)
|
78
|
-
"#{String === msg ? msg : msg.inspect}\n"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
# Declare an attribute accessor with an initial default return value.
|
3
|
-
#
|
4
|
-
# To give attribute <tt>:age</tt> the initial value <tt>25</tt>:
|
5
|
-
#
|
6
|
-
# class Person
|
7
|
-
# attr_accessor_with_default :age, 25
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# person = Person.new
|
11
|
-
# person.age # => 25
|
12
|
-
#
|
13
|
-
# person.age = 26
|
14
|
-
# person.age # => 26
|
15
|
-
#
|
16
|
-
# To give attribute <tt>:element_name</tt> a dynamic default value, evaluated
|
17
|
-
# in scope of self:
|
18
|
-
#
|
19
|
-
# attr_accessor_with_default(:element_name) { name.underscore }
|
20
|
-
#
|
21
|
-
def attr_accessor_with_default(sym, default = Proc.new)
|
22
|
-
ActiveSupport::Deprecation.warn "attr_accessor_with_default is deprecated. Use Ruby instead!"
|
23
|
-
define_method(sym, block_given? ? default : Proc.new { default })
|
24
|
-
module_eval(<<-EVAL, __FILE__, __LINE__ + 1)
|
25
|
-
def #{sym}=(value) # def age=(value)
|
26
|
-
class << self; attr_accessor :#{sym} end # class << self; attr_accessor :age end
|
27
|
-
@#{sym} = value # @age = value
|
28
|
-
end # end
|
29
|
-
EVAL
|
30
|
-
end
|
31
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
if instance_methods[0].is_a?(Symbol)
|
3
|
-
def instance_method_names(*args)
|
4
|
-
instance_methods(*args).map(&:to_s)
|
5
|
-
end
|
6
|
-
|
7
|
-
def method_names(*args)
|
8
|
-
methods(*args).map(&:to_s)
|
9
|
-
end
|
10
|
-
else
|
11
|
-
alias_method :instance_method_names, :instance_methods
|
12
|
-
alias_method :method_names, :methods
|
13
|
-
end
|
14
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require 'active_support/core_ext/module/aliasing'
|
3
|
-
require 'active_support/core_ext/array/extract_options'
|
4
|
-
|
5
|
-
class Module
|
6
|
-
# Synchronize access around a method, delegating synchronization to a
|
7
|
-
# particular mutex. A mutex (either a Mutex, or any object that responds to
|
8
|
-
# #synchronize and yields to a block) must be provided as a final :with option.
|
9
|
-
# The :with option should be a symbol or string, and can represent a method,
|
10
|
-
# constant, or instance or class variable.
|
11
|
-
# Example:
|
12
|
-
# class SharedCache
|
13
|
-
# @@lock = Mutex.new
|
14
|
-
# def expire
|
15
|
-
# ...
|
16
|
-
# end
|
17
|
-
# synchronize :expire, :with => :@@lock
|
18
|
-
# end
|
19
|
-
def synchronize(*methods)
|
20
|
-
options = methods.extract_options!
|
21
|
-
unless options.is_a?(Hash) && with = options[:with]
|
22
|
-
raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)."
|
23
|
-
end
|
24
|
-
|
25
|
-
methods.each do |method|
|
26
|
-
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
|
27
|
-
|
28
|
-
if method_defined?("#{aliased_method}_without_synchronization#{punctuation}")
|
29
|
-
raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
|
30
|
-
end
|
31
|
-
|
32
|
-
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
33
|
-
def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block)
|
34
|
-
#{with}.synchronize do # @@lock.synchronize do
|
35
|
-
#{aliased_method}_without_synchronization#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block)
|
36
|
-
end # end
|
37
|
-
end # end
|
38
|
-
EOS
|
39
|
-
|
40
|
-
alias_method_chain method, :synchronization
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Hack to load json gem first so we can overwrite its to_json.
|
2
|
-
begin
|
3
|
-
require 'json'
|
4
|
-
rescue LoadError
|
5
|
-
end
|
6
|
-
|
7
|
-
# The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting
|
8
|
-
# their default behavior. That said, we need to define the basic to_json method in all of them,
|
9
|
-
# otherwise they will always use to_json gem implementation, which is backwards incompatible in
|
10
|
-
# several cases (for instance, the JSON implementation for Hash does not work) with inheritance
|
11
|
-
# and consequently classes as ActiveSupport::OrderedHash cannot be serialized to json.
|
12
|
-
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
|
13
|
-
klass.class_eval <<-RUBY, __FILE__, __LINE__
|
14
|
-
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
|
15
|
-
def to_json(options = nil)
|
16
|
-
ActiveSupport::JSON.encode(self, options)
|
17
|
-
end
|
18
|
-
RUBY
|
19
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/kernel/singleton_class"
|
2
|
-
|
3
|
-
class Proc #:nodoc:
|
4
|
-
def bind(object)
|
5
|
-
block, time = self, Time.now
|
6
|
-
object.class_eval do
|
7
|
-
method_name = "__bind_#{time.to_i}_#{time.usec}"
|
8
|
-
define_method(method_name, &block)
|
9
|
-
method = instance_method(method_name)
|
10
|
-
remove_method(method_name)
|
11
|
-
method
|
12
|
-
end.bind(object)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Process
|
2
|
-
def self.daemon(nochdir = nil, noclose = nil)
|
3
|
-
exit if fork # Parent exits, child continues.
|
4
|
-
Process.setsid # Become session leader.
|
5
|
-
exit if fork # Zap session leader. See [1].
|
6
|
-
|
7
|
-
unless nochdir
|
8
|
-
Dir.chdir "/" # Release old working directory.
|
9
|
-
end
|
10
|
-
|
11
|
-
File.umask 0000 # Ensure sensible umask. Adjust as needed.
|
12
|
-
|
13
|
-
unless noclose
|
14
|
-
STDIN.reopen "/dev/null" # Free file descriptors and
|
15
|
-
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
|
16
|
-
STDERR.reopen '/dev/null', 'a'
|
17
|
-
end
|
18
|
-
|
19
|
-
trap("TERM") { exit }
|
20
|
-
|
21
|
-
return 0
|
22
|
-
end unless respond_to?(:daemon)
|
23
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/process/daemon'
|
@@ -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,36 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
class FileWatcher
|
3
|
-
class Backend
|
4
|
-
def initialize(path, watcher)
|
5
|
-
@watcher = watcher
|
6
|
-
@path = path
|
7
|
-
end
|
8
|
-
|
9
|
-
def trigger(files)
|
10
|
-
@watcher.trigger(files)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@regex_matchers = {}
|
16
|
-
end
|
17
|
-
|
18
|
-
def watch(pattern, &block)
|
19
|
-
@regex_matchers[pattern] = block
|
20
|
-
end
|
21
|
-
|
22
|
-
def trigger(files)
|
23
|
-
trigger_files = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = [] } }
|
24
|
-
|
25
|
-
files.each do |file, state|
|
26
|
-
@regex_matchers.each do |pattern, block|
|
27
|
-
trigger_files[block][state] << file if pattern === file
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
trigger_files.each do |block, payload|
|
32
|
-
block.call payload
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/kernel/singleton_class'
|
2
|
-
require 'active_support/core_ext/module/aliasing'
|
3
|
-
|
4
|
-
module ActiveSupport
|
5
|
-
module Memoizable
|
6
|
-
def self.memoized_ivar_for(symbol)
|
7
|
-
"@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
|
8
|
-
end
|
9
|
-
|
10
|
-
module InstanceMethods
|
11
|
-
def self.included(base)
|
12
|
-
base.class_eval do
|
13
|
-
unless base.method_defined?(:freeze_without_memoizable)
|
14
|
-
alias_method_chain :freeze, :memoizable
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def freeze_with_memoizable
|
20
|
-
memoize_all unless frozen?
|
21
|
-
freeze_without_memoizable
|
22
|
-
end
|
23
|
-
|
24
|
-
def memoize_all
|
25
|
-
prime_cache ".*"
|
26
|
-
end
|
27
|
-
|
28
|
-
def unmemoize_all
|
29
|
-
flush_cache ".*"
|
30
|
-
end
|
31
|
-
|
32
|
-
def prime_cache(*syms)
|
33
|
-
syms.each do |sym|
|
34
|
-
methods.each do |m|
|
35
|
-
if m.to_s =~ /^_unmemoized_(#{sym})/
|
36
|
-
if method(m).arity == 0
|
37
|
-
__send__($1)
|
38
|
-
else
|
39
|
-
ivar = ActiveSupport::Memoizable.memoized_ivar_for($1)
|
40
|
-
instance_variable_set(ivar, {})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def flush_cache(*syms)
|
48
|
-
syms.each do |sym|
|
49
|
-
(methods + private_methods + protected_methods).each do |m|
|
50
|
-
if m.to_s =~ /^_unmemoized_(#{sym.to_s.gsub(/\?\Z/, '\?')})/
|
51
|
-
ivar = ActiveSupport::Memoizable.memoized_ivar_for($1)
|
52
|
-
instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def memoize(*symbols)
|
60
|
-
symbols.each do |symbol|
|
61
|
-
original_method = :"_unmemoized_#{symbol}"
|
62
|
-
memoized_ivar = ActiveSupport::Memoizable.memoized_ivar_for(symbol)
|
63
|
-
|
64
|
-
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
65
|
-
include InstanceMethods # include InstanceMethods
|
66
|
-
#
|
67
|
-
if method_defined?(:#{original_method}) # if method_defined?(:_unmemoized_mime_type)
|
68
|
-
raise "Already memoized #{symbol}" # raise "Already memoized mime_type"
|
69
|
-
end # end
|
70
|
-
alias #{original_method} #{symbol} # alias _unmemoized_mime_type mime_type
|
71
|
-
#
|
72
|
-
if instance_method(:#{symbol}).arity == 0 # if instance_method(:mime_type).arity == 0
|
73
|
-
def #{symbol}(reload = false) # def mime_type(reload = false)
|
74
|
-
if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty? # if reload || !defined?(@_memoized_mime_type) || @_memoized_mime_type.empty?
|
75
|
-
#{memoized_ivar} = [#{original_method}] # @_memoized_mime_type = [_unmemoized_mime_type]
|
76
|
-
end # end
|
77
|
-
#{memoized_ivar}[0] # @_memoized_mime_type[0]
|
78
|
-
end # end
|
79
|
-
else # else
|
80
|
-
def #{symbol}(*args) # def mime_type(*args)
|
81
|
-
#{memoized_ivar} ||= {} unless frozen? # @_memoized_mime_type ||= {} unless frozen?
|
82
|
-
reload = args.pop if args.last == true || args.last == :reload # reload = args.pop if args.last == true || args.last == :reload
|
83
|
-
#
|
84
|
-
if defined?(#{memoized_ivar}) && #{memoized_ivar} # if defined?(@_memoized_mime_type) && @_memoized_mime_type
|
85
|
-
if !reload && #{memoized_ivar}.has_key?(args) # if !reload && @_memoized_mime_type.has_key?(args)
|
86
|
-
#{memoized_ivar}[args] # @_memoized_mime_type[args]
|
87
|
-
elsif #{memoized_ivar} # elsif @_memoized_mime_type
|
88
|
-
#{memoized_ivar}[args] = #{original_method}(*args) # @_memoized_mime_type[args] = _unmemoized_mime_type(*args)
|
89
|
-
end # end
|
90
|
-
else # else
|
91
|
-
#{original_method}(*args) # _unmemoized_mime_type(*args)
|
92
|
-
end # end
|
93
|
-
end # end
|
94
|
-
end # end
|
95
|
-
#
|
96
|
-
if private_method_defined?(#{original_method.inspect}) # if private_method_defined?(:_unmemoized_mime_type)
|
97
|
-
private #{symbol.inspect} # private :mime_type
|
98
|
-
elsif protected_method_defined?(#{original_method.inspect}) # elsif protected_method_defined?(:_unmemoized_mime_type)
|
99
|
-
protected #{symbol.inspect} # protected :mime_type
|
100
|
-
end # end
|
101
|
-
EOS
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
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'
|