activesupport 3.0.pre → 3.0.0.rc
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.
- data/CHANGELOG +121 -1
- data/README.rdoc +33 -0
- data/lib/active_support.rb +42 -4
- data/lib/active_support/backtrace_cleaner.rb +31 -9
- data/lib/active_support/benchmarkable.rb +1 -0
- data/lib/active_support/buffered_logger.rb +5 -2
- data/lib/active_support/builder.rb +6 -0
- data/lib/active_support/cache.rb +454 -84
- data/lib/active_support/cache/compressed_mem_cache_store.rb +6 -13
- data/lib/active_support/cache/file_store.rb +140 -41
- data/lib/active_support/cache/mem_cache_store.rb +121 -76
- data/lib/active_support/cache/memory_store.rb +127 -27
- data/lib/active_support/cache/strategy/local_cache.rb +111 -58
- data/lib/active_support/cache/synchronized_memory_store.rb +2 -38
- data/lib/active_support/callbacks.rb +105 -76
- data/lib/active_support/configurable.rb +19 -18
- data/lib/active_support/core_ext/array.rb +1 -0
- data/lib/active_support/core_ext/array/access.rb +1 -1
- data/lib/active_support/core_ext/array/conversions.rb +29 -54
- data/lib/active_support/core_ext/array/extract_options.rb +16 -1
- data/lib/active_support/core_ext/array/grouping.rb +1 -1
- data/lib/active_support/core_ext/array/random_access.rb +26 -5
- data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
- data/lib/active_support/core_ext/array/wrap.rb +13 -9
- data/lib/active_support/core_ext/benchmark.rb +0 -12
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +2 -0
- data/lib/active_support/core_ext/class.rb +2 -1
- data/lib/active_support/core_ext/class/attribute.rb +67 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +33 -27
- data/lib/active_support/core_ext/class/delegating_attributes.rb +35 -41
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +23 -14
- data/lib/active_support/core_ext/class/subclasses.rb +50 -0
- data/lib/active_support/core_ext/date/calculations.rb +35 -12
- data/lib/active_support/core_ext/date/conversions.rb +5 -5
- data/lib/active_support/core_ext/date/zones.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +3 -1
- data/lib/active_support/core_ext/date_time/conversions.rb +24 -5
- data/lib/active_support/core_ext/date_time/zones.rb +4 -0
- data/lib/active_support/core_ext/enumerable.rb +5 -9
- data/lib/active_support/core_ext/exception.rb +0 -47
- data/lib/active_support/core_ext/file.rb +1 -0
- data/lib/active_support/core_ext/file/atomic.rb +3 -2
- data/lib/active_support/core_ext/file/path.rb +5 -0
- data/lib/active_support/core_ext/float/rounding.rb +3 -2
- data/lib/active_support/core_ext/hash/conversions.rb +65 -145
- data/lib/active_support/core_ext/hash/deep_merge.rb +6 -7
- data/lib/active_support/core_ext/hash/except.rb +8 -1
- data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -0
- data/lib/active_support/core_ext/hash/keys.rb +10 -11
- data/lib/active_support/core_ext/hash/slice.rb +6 -0
- data/lib/active_support/core_ext/integer.rb +1 -1
- data/lib/active_support/core_ext/integer/multiple.rb +6 -0
- data/lib/active_support/core_ext/kernel.rb +1 -1
- data/lib/active_support/core_ext/kernel/debugger.rb +3 -2
- data/lib/active_support/core_ext/kernel/reporting.rb +2 -1
- data/lib/active_support/core_ext/kernel/requires.rb +2 -2
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/load_error.rb +17 -30
- data/lib/active_support/core_ext/logger.rb +2 -40
- data/lib/active_support/core_ext/module.rb +5 -3
- data/lib/active_support/core_ext/module/aliasing.rb +1 -1
- data/lib/active_support/core_ext/module/anonymous.rb +24 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
- data/lib/active_support/core_ext/module/attribute_accessors.rb +20 -22
- data/lib/active_support/core_ext/module/delegation.rb +21 -10
- data/lib/active_support/core_ext/module/introspection.rb +8 -8
- data/lib/active_support/core_ext/module/method_names.rb +14 -0
- data/lib/active_support/core_ext/module/reachable.rb +10 -0
- data/lib/active_support/core_ext/module/remove_method.rb +11 -0
- data/lib/active_support/core_ext/module/synchronization.rb +2 -1
- data/lib/active_support/core_ext/name_error.rb +3 -1
- data/lib/active_support/core_ext/object.rb +5 -3
- data/lib/active_support/core_ext/object/blank.rb +20 -2
- data/lib/active_support/core_ext/object/conversions.rb +2 -16
- data/lib/active_support/core_ext/object/duplicable.rb +23 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
- data/lib/active_support/core_ext/object/to_json.rb +19 -0
- data/lib/active_support/core_ext/object/to_param.rb +49 -0
- data/lib/active_support/core_ext/object/to_query.rb +27 -0
- data/lib/active_support/core_ext/object/with_options.rb +2 -0
- data/lib/active_support/core_ext/proc.rb +4 -4
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/regexp.rb +0 -22
- data/lib/active_support/core_ext/rexml.rb +4 -1
- data/lib/active_support/core_ext/string.rb +3 -2
- data/lib/active_support/core_ext/string/access.rb +4 -2
- data/lib/active_support/core_ext/string/conversions.rb +28 -1
- data/lib/active_support/core_ext/string/encoding.rb +11 -0
- data/lib/active_support/core_ext/string/exclude.rb +6 -0
- data/lib/active_support/core_ext/string/filters.rb +29 -0
- data/lib/active_support/core_ext/string/inflections.rb +12 -12
- data/lib/active_support/core_ext/string/interpolation.rb +2 -92
- data/lib/active_support/core_ext/string/multibyte.rb +16 -19
- data/lib/active_support/core_ext/string/output_safety.rb +101 -35
- data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -14
- data/lib/active_support/core_ext/string/xchar.rb +1 -1
- data/lib/active_support/core_ext/time/calculations.rb +14 -7
- data/lib/active_support/core_ext/time/conversions.rb +1 -0
- data/lib/active_support/core_ext/time/marshal.rb +56 -0
- data/lib/active_support/core_ext/time/zones.rb +2 -5
- data/lib/active_support/core_ext/uri.rb +10 -4
- data/lib/active_support/dependencies.rb +200 -197
- data/lib/active_support/dependencies/autoload.rb +50 -0
- data/lib/active_support/deprecation/behaviors.rb +13 -9
- data/lib/active_support/deprecation/method_wrappers.rb +10 -9
- data/lib/active_support/deprecation/proxy_wrappers.rb +7 -0
- data/lib/active_support/deprecation/reporting.rb +5 -3
- data/lib/active_support/descendants_tracker.rb +43 -0
- data/lib/active_support/duration.rb +8 -4
- data/lib/active_support/file_update_checker.rb +36 -0
- data/lib/active_support/hash_with_indifferent_access.rb +9 -1
- data/lib/active_support/i18n.rb +9 -0
- data/lib/active_support/i18n_railtie.rb +81 -0
- data/lib/active_support/inflections.rb +1 -1
- data/lib/active_support/inflector.rb +4 -407
- data/lib/active_support/inflector/inflections.rb +211 -0
- data/lib/active_support/inflector/methods.rb +151 -0
- data/lib/active_support/inflector/transliterate.rb +97 -0
- data/lib/active_support/json/backends/jsongem.rb +12 -9
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/backends/yaml.rb +1 -1
- data/lib/active_support/json/decoding.rb +17 -2
- data/lib/active_support/json/encoding.rb +48 -31
- data/lib/active_support/json/variable.rb +2 -4
- data/lib/active_support/lazy_load_hooks.rb +27 -0
- data/lib/active_support/locale/en.yml +5 -2
- data/lib/active_support/log_subscriber.rb +123 -0
- data/lib/active_support/log_subscriber/test_helper.rb +99 -0
- data/lib/active_support/memoizable.rb +1 -1
- data/lib/active_support/message_encryptor.rb +1 -0
- data/lib/active_support/message_verifier.rb +2 -1
- data/lib/active_support/multibyte.rb +8 -23
- data/lib/active_support/multibyte/chars.rb +213 -446
- data/lib/active_support/multibyte/unicode.rb +392 -0
- data/lib/active_support/multibyte/utils.rb +6 -7
- data/lib/active_support/notifications.rb +29 -122
- data/lib/active_support/notifications/fanout.rb +61 -0
- data/lib/active_support/notifications/instrumenter.rb +54 -0
- data/lib/active_support/ordered_hash.rb +59 -14
- data/lib/active_support/ordered_options.rb +6 -0
- data/lib/active_support/railtie.rb +60 -0
- data/lib/active_support/rescuable.rb +7 -4
- data/lib/active_support/ruby/shim.rb +4 -6
- data/lib/active_support/test_case.rb +2 -7
- data/lib/active_support/testing/assertions.rb +15 -0
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/isolation.rb +64 -17
- data/lib/active_support/testing/performance.rb +306 -335
- data/lib/active_support/testing/setup_and_teardown.rb +51 -29
- data/lib/active_support/time.rb +24 -3
- data/lib/active_support/time_with_zone.rb +10 -14
- data/lib/active_support/values/time_zone.rb +192 -234
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +3 -2
- data/lib/active_support/whiny_nil.rb +9 -7
- data/lib/active_support/xml_mini.rb +130 -1
- data/lib/active_support/xml_mini/jdom.rb +2 -0
- data/lib/active_support/xml_mini/libxml.rb +23 -86
- data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
- data/lib/active_support/xml_mini/nokogiri.rb +27 -24
- data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
- data/lib/active_support/xml_mini/rexml.rb +8 -2
- metadata +62 -195
- data/README +0 -43
- data/lib/active_support/autoload.rb +0 -28
- data/lib/active_support/core_ext/boolean.rb +0 -1
- data/lib/active_support/core_ext/boolean/conversions.rb +0 -11
- data/lib/active_support/core_ext/class/removal.rb +0 -53
- data/lib/active_support/core_ext/date.rb +0 -7
- data/lib/active_support/core_ext/date_time.rb +0 -5
- data/lib/active_support/core_ext/integer/even_odd.rb +0 -16
- data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
- data/lib/active_support/core_ext/module/inclusion.rb +0 -30
- data/lib/active_support/core_ext/module/loading.rb +0 -23
- data/lib/active_support/core_ext/nil.rb +0 -1
- data/lib/active_support/core_ext/nil/conversions.rb +0 -5
- data/lib/active_support/core_ext/object/extending.rb +0 -80
- data/lib/active_support/core_ext/object/metaclass.rb +0 -13
- data/lib/active_support/core_ext/object/misc.rb +0 -3
- data/lib/active_support/core_ext/object/returning.rb +0 -42
- data/lib/active_support/core_ext/object/tap.rb +0 -16
- data/lib/active_support/core_ext/string/bytesize.rb +0 -5
- data/lib/active_support/core_ext/string/iterators.rb +0 -13
- data/lib/active_support/core_ext/symbol.rb +0 -1
- data/lib/active_support/core_ext/symbol/to_proc.rb +0 -14
- data/lib/active_support/core_ext/time.rb +0 -10
- data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +0 -22
- data/lib/active_support/deprecated_callbacks.rb +0 -283
- data/lib/active_support/multibyte/unicode_database.rb +0 -71
- data/lib/active_support/vendor.rb +0 -16
- data/lib/active_support/vendor/builder-2.1.2/lib/blankslate.rb +0 -113
- data/lib/active_support/vendor/builder-2.1.2/lib/builder.rb +0 -13
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/blankslate.rb +0 -20
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/css.rb +0 -250
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/xchar.rb +0 -115
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlbase.rb +0 -139
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlevents.rb +0 -63
- data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlmarkup.rb +0 -328
- data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
- data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
- data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -204
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -215
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
- data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
- data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
- data/lib/active_support/vendor/memcache-client-1.7.5/lib/memcache.rb +0 -1133
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone.rb +0 -47
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone_info.rb +0 -228
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Algiers.rb +0 -55
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Cairo.rb +0 -219
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Casablanca.rb +0 -42
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Harare.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Monrovia.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Nairobi.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Bogota.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Caracas.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chicago.rb +0 -283
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chihuahua.rb +0 -136
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Denver.rb +0 -204
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Godthab.rb +0 -161
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Guatemala.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Halifax.rb +0 -274
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Juneau.rb +0 -194
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/La_Paz.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Lima.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Los_Angeles.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mazatlan.rb +0 -139
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mexico_City.rb +0 -144
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Monterrey.rb +0 -131
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/New_York.rb +0 -282
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Phoenix.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Regina.rb +0 -74
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Santiago.rb +0 -205
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/St_Johns.rb +0 -288
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Tijuana.rb +0 -196
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Almaty.rb +0 -67
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baghdad.rb +0 -73
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baku.rb +0 -161
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Bangkok.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Chongqing.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Colombo.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Dhaka.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jakarta.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kabul.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Karachi.rb +0 -32
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kathmandu.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kolkata.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuwait.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Magadan.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Muscat.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Rangoon.rb +0 -24
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Riyadh.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Seoul.rb +0 -34
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Shanghai.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Singapore.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Taipei.rb +0 -59
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tashkent.rb +0 -47
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tehran.rb +0 -121
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tokyo.rb +0 -30
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Urumqi.rb +0 -33
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yerevan.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Azores.rb +0 -270
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Adelaide.rb +0 -187
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Brisbane.rb +0 -35
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Darwin.rb +0 -29
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Hobart.rb +0 -193
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Melbourne.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Perth.rb +0 -37
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Sydney.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Etc/UTC.rb +0 -16
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Athens.rb +0 -185
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Belgrade.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Berlin.rb +0 -188
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bratislava.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Brussels.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bucharest.rb +0 -181
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Budapest.rb +0 -197
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Dublin.rb +0 -276
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Helsinki.rb +0 -163
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Istanbul.rb +0 -218
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Kiev.rb +0 -168
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Lisbon.rb +0 -268
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/London.rb +0 -288
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Madrid.rb +0 -211
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Minsk.rb +0 -170
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Moscow.rb +0 -181
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Paris.rb +0 -232
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Prague.rb +0 -187
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Riga.rb +0 -176
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Rome.rb +0 -215
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Skopje.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sofia.rb +0 -173
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Stockholm.rb +0 -165
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Tallinn.rb +0 -172
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vienna.rb +0 -183
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vilnius.rb +0 -170
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Warsaw.rb +0 -212
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Zagreb.rb +0 -13
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Auckland.rb +0 -202
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Fiji.rb +0 -23
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Guam.rb +0 -22
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Majuro.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Midway.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Noumea.rb +0 -25
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/info_timezone.rb +0 -52
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone.rb +0 -51
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone_info.rb +0 -44
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/offset_rationals.rb +0 -98
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/ruby_core_support.rb +0 -56
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/time_or_datetime.rb +0 -292
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone.rb +0 -508
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_definition.rb +0 -56
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_info.rb +0 -40
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_offset_info.rb +0 -94
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_period.rb +0 -198
- data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_transition_info.rb +0 -129
@@ -23,15 +23,18 @@ module ActiveSupport
|
|
23
23
|
private
|
24
24
|
def convert_dates_from(data)
|
25
25
|
case data
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
when nil
|
27
|
+
nil
|
28
|
+
when DATE_REGEX
|
29
|
+
DateTime.parse(data)
|
30
|
+
when Array
|
31
|
+
data.map! { |d| convert_dates_from(d) }
|
32
|
+
when Hash
|
33
|
+
data.each do |key, value|
|
34
|
+
data[key] = convert_dates_from(value)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
data
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yajl' unless defined?(Yajl)
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module JSON
|
5
|
+
module Backends
|
6
|
+
module Yajl
|
7
|
+
ParseError = ::Yajl::ParseError
|
8
|
+
extend self
|
9
|
+
|
10
|
+
# Parses a JSON string or IO and convert it into an object
|
11
|
+
def decode(json)
|
12
|
+
data = ::Yajl::Parser.new.parse(json)
|
13
|
+
if ActiveSupport.parse_json_times
|
14
|
+
convert_dates_from(data)
|
15
|
+
else
|
16
|
+
data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def convert_dates_from(data)
|
22
|
+
case data
|
23
|
+
when nil
|
24
|
+
nil
|
25
|
+
when DATE_REGEX
|
26
|
+
DateTime.parse(data)
|
27
|
+
when Array
|
28
|
+
data.map! { |d| convert_dates_from(d) }
|
29
|
+
when Hash
|
30
|
+
data.each do |key, value|
|
31
|
+
data[key] = convert_dates_from(value)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
data
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -6,12 +6,15 @@ module ActiveSupport
|
|
6
6
|
mattr_accessor :parse_json_times
|
7
7
|
|
8
8
|
module JSON
|
9
|
+
# Listed in order of preference.
|
10
|
+
DECODERS = %w(Yajl Yaml)
|
11
|
+
|
9
12
|
class << self
|
10
13
|
attr_reader :parse_error
|
11
14
|
delegate :decode, :to => :backend
|
12
15
|
|
13
16
|
def backend
|
14
|
-
|
17
|
+
set_default_backend unless defined?(@backend)
|
15
18
|
@backend
|
16
19
|
end
|
17
20
|
|
@@ -19,7 +22,7 @@ module ActiveSupport
|
|
19
22
|
if name.is_a?(Module)
|
20
23
|
@backend = name
|
21
24
|
else
|
22
|
-
require "active_support/json/backends/#{name.to_s.downcase}
|
25
|
+
require "active_support/json/backends/#{name.to_s.downcase}"
|
23
26
|
@backend = ActiveSupport::JSON::Backends::const_get(name)
|
24
27
|
end
|
25
28
|
@parse_error = @backend::ParseError
|
@@ -31,6 +34,18 @@ module ActiveSupport
|
|
31
34
|
ensure
|
32
35
|
self.backend = old_backend
|
33
36
|
end
|
37
|
+
|
38
|
+
def set_default_backend
|
39
|
+
DECODERS.find do |name|
|
40
|
+
begin
|
41
|
+
self.backend = name
|
42
|
+
true
|
43
|
+
rescue LoadError
|
44
|
+
# Try next decoder.
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
34
49
|
end
|
35
50
|
end
|
36
51
|
end
|
@@ -1,21 +1,18 @@
|
|
1
|
-
|
1
|
+
require 'active_support/core_ext/object/to_json'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
require 'active_support/deprecation'
|
4
|
+
require 'active_support/json/variable'
|
5
|
+
|
6
|
+
require 'bigdecimal'
|
7
|
+
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
|
2
8
|
require 'active_support/core_ext/array/wrap'
|
3
9
|
require 'active_support/core_ext/hash/except'
|
4
10
|
require 'active_support/core_ext/hash/slice'
|
5
|
-
require 'active_support/core_ext/module/delegation'
|
6
11
|
require 'active_support/core_ext/object/instance_variables'
|
7
|
-
require '
|
8
|
-
|
9
|
-
require 'active_support/core_ext/date_time/conversions'
|
12
|
+
require 'time'
|
10
13
|
require 'active_support/core_ext/time/conversions'
|
11
|
-
require 'active_support/
|
12
|
-
require 'active_support/
|
13
|
-
|
14
|
-
# Hack to load json gem first so we can overwrite its to_json.
|
15
|
-
begin
|
16
|
-
require 'json'
|
17
|
-
rescue LoadError
|
18
|
-
end
|
14
|
+
require 'active_support/core_ext/date_time/conversions'
|
15
|
+
require 'active_support/core_ext/date/conversions'
|
19
16
|
|
20
17
|
module ActiveSupport
|
21
18
|
class << self
|
@@ -68,6 +65,15 @@ module ActiveSupport
|
|
68
65
|
|
69
66
|
|
70
67
|
ESCAPED_CHARS = {
|
68
|
+
"\x00" => '\u0000', "\x01" => '\u0001', "\x02" => '\u0002',
|
69
|
+
"\x03" => '\u0003', "\x04" => '\u0004', "\x05" => '\u0005',
|
70
|
+
"\x06" => '\u0006', "\x07" => '\u0007', "\x0B" => '\u000B',
|
71
|
+
"\x0E" => '\u000E', "\x0F" => '\u000F', "\x10" => '\u0010',
|
72
|
+
"\x11" => '\u0011', "\x12" => '\u0012', "\x13" => '\u0013',
|
73
|
+
"\x14" => '\u0014', "\x15" => '\u0015', "\x16" => '\u0016',
|
74
|
+
"\x17" => '\u0017', "\x18" => '\u0018', "\x19" => '\u0019',
|
75
|
+
"\x1A" => '\u001A', "\x1B" => '\u001B', "\x1C" => '\u001C',
|
76
|
+
"\x1D" => '\u001D', "\x1E" => '\u001E', "\x1F" => '\u001F',
|
71
77
|
"\010" => '\b',
|
72
78
|
"\f" => '\f',
|
73
79
|
"\n" => '\n',
|
@@ -89,14 +95,16 @@ module ActiveSupport
|
|
89
95
|
def escape_html_entities_in_json=(value)
|
90
96
|
self.escape_regex = \
|
91
97
|
if @escape_html_entities_in_json = value
|
92
|
-
/[\
|
98
|
+
/[\x00-\x1F"\\><&]/
|
93
99
|
else
|
94
|
-
/[\
|
100
|
+
/[\x00-\x1F"\\]/
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
98
104
|
def escape(string)
|
99
|
-
|
105
|
+
if string.respond_to?(:force_encoding)
|
106
|
+
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
|
107
|
+
end
|
100
108
|
json = string.
|
101
109
|
gsub(escape_regex) { |s| ESCAPED_CHARS[s] }.
|
102
110
|
gsub(/([\xC0-\xDF][\x80-\xBF]|
|
@@ -104,11 +112,14 @@ module ActiveSupport
|
|
104
112
|
[\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|
|
105
113
|
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&')
|
106
114
|
}
|
107
|
-
%("#{json}")
|
115
|
+
json = %("#{json}")
|
116
|
+
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
|
117
|
+
json
|
108
118
|
end
|
109
119
|
end
|
110
120
|
|
111
|
-
self.
|
121
|
+
self.use_standard_json_time_format = true
|
122
|
+
self.escape_html_entities_in_json = false
|
112
123
|
end
|
113
124
|
|
114
125
|
CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
|
@@ -116,18 +127,13 @@ module ActiveSupport
|
|
116
127
|
end
|
117
128
|
|
118
129
|
class Object
|
119
|
-
|
120
|
-
|
121
|
-
|
130
|
+
def as_json(options = nil) #:nodoc:
|
131
|
+
if respond_to?(:to_hash)
|
132
|
+
to_hash
|
133
|
+
else
|
134
|
+
instance_values
|
135
|
+
end
|
122
136
|
end
|
123
|
-
|
124
|
-
def as_json(options = nil) instance_values end #:nodoc:
|
125
|
-
end
|
126
|
-
|
127
|
-
# A string that returns itself as its JSON-encoded form.
|
128
|
-
class ActiveSupport::JSON::Variable < String
|
129
|
-
def as_json(options = nil) self end #:nodoc:
|
130
|
-
def encode_json(encoder) self end #:nodoc:
|
131
137
|
end
|
132
138
|
|
133
139
|
class TrueClass
|
@@ -159,9 +165,20 @@ class Numeric
|
|
159
165
|
def encode_json(encoder) to_s end #:nodoc:
|
160
166
|
end
|
161
167
|
|
168
|
+
class BigDecimal
|
169
|
+
# A BigDecimal would be naturally represented as a JSON number. Most libraries,
|
170
|
+
# however, parse non-integer JSON numbers directly as floats. Clients using
|
171
|
+
# those libraries would get in general a wrong number and no way to recover
|
172
|
+
# other than manually inspecting the string with the JSON code itself.
|
173
|
+
#
|
174
|
+
# That's why a JSON string is returned. The JSON literal is not numeric, but if
|
175
|
+
# the other end knows by contract that the data is supposed to be a BigDecimal,
|
176
|
+
# it still has the chance to post-process the string and get the real value.
|
177
|
+
def as_json(options = nil) to_s end #:nodoc:
|
178
|
+
end
|
179
|
+
|
162
180
|
class Regexp
|
163
|
-
def as_json(options = nil)
|
164
|
-
def encode_json(encoder) inspect end #:nodoc:
|
181
|
+
def as_json(options = nil) to_s end #:nodoc:
|
165
182
|
end
|
166
183
|
|
167
184
|
module Enumerable
|
@@ -2,10 +2,8 @@ module ActiveSupport
|
|
2
2
|
module JSON
|
3
3
|
# A string that returns itself as its JSON-encoded form.
|
4
4
|
class Variable < String
|
5
|
-
|
6
|
-
|
7
|
-
self
|
8
|
-
end
|
5
|
+
def as_json(options = nil) self end #:nodoc:
|
6
|
+
def encode_json(encoder) self end #:nodoc:
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
@load_hooks = Hash.new {|h,k| h[k] = [] }
|
3
|
+
@loaded = {}
|
4
|
+
|
5
|
+
def self.on_load(name, options = {}, &block)
|
6
|
+
if base = @loaded[name]
|
7
|
+
execute_hook(base, options, block)
|
8
|
+
else
|
9
|
+
@load_hooks[name] << [block, options]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.execute_hook(base, options, block)
|
14
|
+
if options[:yield]
|
15
|
+
block.call(base)
|
16
|
+
else
|
17
|
+
base.instance_eval(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run_load_hooks(name, base = Object)
|
22
|
+
@loaded[name] = base
|
23
|
+
@load_hooks[name].each do |hook, options|
|
24
|
+
execute_hook(base, options, hook)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -14,8 +14,11 @@ en:
|
|
14
14
|
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
15
15
|
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
16
16
|
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
17
|
-
# Used in date_select and
|
18
|
-
order:
|
17
|
+
# Used in date_select and datetime_select.
|
18
|
+
order:
|
19
|
+
- :year
|
20
|
+
- :month
|
21
|
+
- :day
|
19
22
|
|
20
23
|
time:
|
21
24
|
formats:
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
# ActiveSupport::LogSubscriber is an object set to consume ActiveSupport::Notifications
|
6
|
+
# with solely purpose of logging. The log subscriber dispatches notifications to a
|
7
|
+
# regirested object based on its given namespace.
|
8
|
+
#
|
9
|
+
# An example would be Active Record log subscriber responsible for logging queries:
|
10
|
+
#
|
11
|
+
# module ActiveRecord
|
12
|
+
# class LogSubscriber < ActiveSupport::LogSubscriber
|
13
|
+
# def sql(event)
|
14
|
+
# "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# And it's finally registed as:
|
20
|
+
#
|
21
|
+
# ActiveRecord::LogSubscriber.attach_to :active_record
|
22
|
+
#
|
23
|
+
# Since we need to know all instance methods before attaching the log subscriber,
|
24
|
+
# the line above should be called after your ActiveRecord::LogSubscriber definition.
|
25
|
+
#
|
26
|
+
# After configured, whenever a "sql.active_record" notification is published,
|
27
|
+
# it will properly dispatch the event (ActiveSupport::Notifications::Event) to
|
28
|
+
# the sql method.
|
29
|
+
#
|
30
|
+
# Log subscriber also has some helpers to deal with logging and automatically flushes
|
31
|
+
# all logs when the request finishes (via action_dispatch.callback notification) in
|
32
|
+
# a Rails environment.
|
33
|
+
class LogSubscriber
|
34
|
+
mattr_accessor :colorize_logging
|
35
|
+
self.colorize_logging = true
|
36
|
+
|
37
|
+
class_attribute :logger
|
38
|
+
|
39
|
+
class << self
|
40
|
+
remove_method :logger
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.logger
|
44
|
+
@logger ||= Rails.logger if defined?(Rails)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Embed in a String to clear all previous ANSI sequences.
|
48
|
+
CLEAR = "\e[0m"
|
49
|
+
BOLD = "\e[1m"
|
50
|
+
|
51
|
+
# Colors
|
52
|
+
BLACK = "\e[30m"
|
53
|
+
RED = "\e[31m"
|
54
|
+
GREEN = "\e[32m"
|
55
|
+
YELLOW = "\e[33m"
|
56
|
+
BLUE = "\e[34m"
|
57
|
+
MAGENTA = "\e[35m"
|
58
|
+
CYAN = "\e[36m"
|
59
|
+
WHITE = "\e[37m"
|
60
|
+
|
61
|
+
def self.attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notifications)
|
62
|
+
log_subscribers << log_subscriber
|
63
|
+
@@flushable_loggers = nil
|
64
|
+
|
65
|
+
log_subscriber.public_methods(false).each do |event|
|
66
|
+
next if 'call' == event.to_s
|
67
|
+
|
68
|
+
notifier.subscribe("#{event}.#{namespace}", log_subscriber)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.log_subscribers
|
73
|
+
@@log_subscribers ||= []
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.flushable_loggers
|
77
|
+
@@flushable_loggers ||= begin
|
78
|
+
loggers = log_subscribers.map(&:logger)
|
79
|
+
loggers.uniq!
|
80
|
+
loggers.select { |l| l.respond_to?(:flush) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Flush all log_subscribers' logger.
|
85
|
+
def self.flush_all!
|
86
|
+
flushable_loggers.each(&:flush)
|
87
|
+
end
|
88
|
+
|
89
|
+
def call(message, *args)
|
90
|
+
return unless logger
|
91
|
+
|
92
|
+
method = message.split('.').first
|
93
|
+
begin
|
94
|
+
send(method, ActiveSupport::Notifications::Event.new(message, *args))
|
95
|
+
rescue Exception => e
|
96
|
+
logger.error "Could not log #{message.inspect} event. #{e.class}: #{e.message}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
%w(info debug warn error fatal unknown).each do |level|
|
103
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
104
|
+
def #{level}(*args, &block)
|
105
|
+
return unless logger
|
106
|
+
logger.#{level}(*args, &block)
|
107
|
+
end
|
108
|
+
METHOD
|
109
|
+
end
|
110
|
+
|
111
|
+
# Set color by using a string or one of the defined constants. If a third
|
112
|
+
# option is set to true, it also adds bold to the string. This is based
|
113
|
+
# on Highline implementation and it automatically appends CLEAR to the end
|
114
|
+
# of the returned String.
|
115
|
+
#
|
116
|
+
def color(text, color, bold=false)
|
117
|
+
return text unless colorize_logging
|
118
|
+
color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
|
119
|
+
bold = bold ? BOLD : ""
|
120
|
+
"#{bold}#{color}#{text}#{CLEAR}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'active_support/log_subscriber'
|
2
|
+
require 'active_support/buffered_logger'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
class LogSubscriber
|
6
|
+
# Provides some helpers to deal with testing log subscribers by setting up
|
7
|
+
# notifications. Take for instance Active Record subscriber tests:
|
8
|
+
#
|
9
|
+
# class SyncLogSubscriberTest < ActiveSupport::TestCase
|
10
|
+
# include ActiveSupport::LogSubscriber::TestHelper
|
11
|
+
#
|
12
|
+
# def setup
|
13
|
+
# ActiveRecord::LogSubscriber.attach_to(:active_record)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def test_basic_query_logging
|
17
|
+
# Developer.all
|
18
|
+
# wait
|
19
|
+
# assert_equal 1, @logger.logged(:debug).size
|
20
|
+
# assert_match /Developer Load/, @logger.logged(:debug).last
|
21
|
+
# assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# All you need to do is to ensure that your log subscriber is added to Rails::Subscriber,
|
26
|
+
# as in the second line of the code above. The test helpers is reponsible for setting
|
27
|
+
# up the queue, subscriptions and turning colors in logs off.
|
28
|
+
#
|
29
|
+
# The messages are available in the @logger instance, which is a logger with limited
|
30
|
+
# powers (it actually do not send anything to your output), and you can collect them
|
31
|
+
# doing @logger.logged(level), where level is the level used in logging, like info,
|
32
|
+
# debug, warn and so on.
|
33
|
+
#
|
34
|
+
module TestHelper
|
35
|
+
def setup
|
36
|
+
@logger = MockLogger.new
|
37
|
+
@notifier = ActiveSupport::Notifications::Fanout.new
|
38
|
+
|
39
|
+
ActiveSupport::LogSubscriber.colorize_logging = false
|
40
|
+
|
41
|
+
set_logger(@logger)
|
42
|
+
ActiveSupport::Notifications.notifier = @notifier
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
set_logger(nil)
|
47
|
+
ActiveSupport::Notifications.notifier = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
class MockLogger
|
51
|
+
include ActiveSupport::BufferedLogger::Severity
|
52
|
+
|
53
|
+
attr_reader :flush_count
|
54
|
+
attr_accessor :level
|
55
|
+
|
56
|
+
def initialize(level = DEBUG)
|
57
|
+
@flush_count = 0
|
58
|
+
@level = level
|
59
|
+
@logged = Hash.new { |h,k| h[k] = [] }
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(level, message)
|
63
|
+
@logged[level] << message
|
64
|
+
end
|
65
|
+
|
66
|
+
def logged(level)
|
67
|
+
@logged[level].compact.map { |l| l.to_s.strip }
|
68
|
+
end
|
69
|
+
|
70
|
+
def flush
|
71
|
+
@flush_count += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
ActiveSupport::BufferedLogger::Severity.constants.each do |severity|
|
75
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
76
|
+
def #{severity.downcase}?
|
77
|
+
#{severity} >= @level
|
78
|
+
end
|
79
|
+
EOT
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Wait notifications to be published.
|
84
|
+
def wait
|
85
|
+
@notifier.wait
|
86
|
+
end
|
87
|
+
|
88
|
+
# Overwrite if you use another logger in your log subscriber:
|
89
|
+
#
|
90
|
+
# def logger
|
91
|
+
# ActiveRecord::Base.logger = @logger
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
def set_logger(logger)
|
95
|
+
ActiveSupport::LogSubscriber.logger = logger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|