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
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_support/core_ext/module/anonymous'
|
2
|
+
require 'active_support/core_ext/module/reachable'
|
3
|
+
|
4
|
+
class Class #:nodoc:
|
5
|
+
# Rubinius
|
6
|
+
if defined?(Class.__subclasses__)
|
7
|
+
alias :subclasses :__subclasses__
|
8
|
+
|
9
|
+
def descendants
|
10
|
+
descendants = []
|
11
|
+
__subclasses__.each do |k|
|
12
|
+
descendants << k
|
13
|
+
descendants.concat k.descendants
|
14
|
+
end
|
15
|
+
descendants
|
16
|
+
end
|
17
|
+
else # MRI
|
18
|
+
begin
|
19
|
+
ObjectSpace.each_object(Class.new) {}
|
20
|
+
|
21
|
+
def descendants
|
22
|
+
descendants = []
|
23
|
+
ObjectSpace.each_object(class << self; self; end) do |k|
|
24
|
+
descendants.unshift k unless k == self
|
25
|
+
end
|
26
|
+
descendants
|
27
|
+
end
|
28
|
+
rescue StandardError # JRuby
|
29
|
+
def descendants
|
30
|
+
descendants = []
|
31
|
+
ObjectSpace.each_object(Class) do |k|
|
32
|
+
descendants.unshift k if k < self
|
33
|
+
end
|
34
|
+
descendants.uniq!
|
35
|
+
descendants
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns an array with the direct children of +self+.
|
40
|
+
#
|
41
|
+
# Integer.subclasses # => [Bignum, Fixnum]
|
42
|
+
def subclasses
|
43
|
+
subclasses, chain = [], descendants
|
44
|
+
chain.each do |k|
|
45
|
+
subclasses << k unless chain.any? { |c| c > k }
|
46
|
+
end
|
47
|
+
subclasses
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,15 +1,37 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'active_support/duration'
|
3
|
+
require 'active_support/core_ext/object/acts_like'
|
4
|
+
require 'active_support/core_ext/date/zones'
|
5
|
+
require 'active_support/core_ext/time/zones'
|
2
6
|
|
3
7
|
class Date
|
8
|
+
if RUBY_VERSION < '1.9'
|
9
|
+
undef :>>
|
10
|
+
|
11
|
+
# Backported from 1.9. The one in 1.8 leads to incorrect next_month and
|
12
|
+
# friends for dates where the calendar reform is involved. It additionally
|
13
|
+
# prevents an infinite loop fixed in r27013.
|
14
|
+
def >>(n)
|
15
|
+
y, m = (year * 12 + (mon - 1) + n).divmod(12)
|
16
|
+
m, = (m + 1) .divmod(1)
|
17
|
+
d = mday
|
18
|
+
until jd2 = self.class.valid_civil?(y, m, d, start)
|
19
|
+
d -= 1
|
20
|
+
raise ArgumentError, 'invalid date' unless d > 0
|
21
|
+
end
|
22
|
+
self + (jd2 - jd)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
4
26
|
class << self
|
5
27
|
# Returns a new Date representing the date 1 day ago (i.e. yesterday's date).
|
6
28
|
def yesterday
|
7
|
-
::Date.
|
29
|
+
::Date.current.yesterday
|
8
30
|
end
|
9
31
|
|
10
32
|
# Returns a new Date representing the date 1 day after today (i.e. tomorrow's date).
|
11
33
|
def tomorrow
|
12
|
-
::Date.
|
34
|
+
::Date.current.tomorrow
|
13
35
|
end
|
14
36
|
|
15
37
|
# Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
|
@@ -36,19 +58,19 @@ class Date
|
|
36
58
|
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
|
37
59
|
# and then subtracts the specified number of seconds
|
38
60
|
def ago(seconds)
|
39
|
-
|
61
|
+
to_time_in_current_zone.since(-seconds)
|
40
62
|
end
|
41
63
|
|
42
64
|
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
|
43
65
|
# and then adds the specified number of seconds
|
44
66
|
def since(seconds)
|
45
|
-
|
67
|
+
to_time_in_current_zone.since(seconds)
|
46
68
|
end
|
47
69
|
alias :in :since
|
48
70
|
|
49
71
|
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
|
50
72
|
def beginning_of_day
|
51
|
-
|
73
|
+
to_time_in_current_zone
|
52
74
|
end
|
53
75
|
alias :midnight :beginning_of_day
|
54
76
|
alias :at_midnight :beginning_of_day
|
@@ -56,7 +78,7 @@ class Date
|
|
56
78
|
|
57
79
|
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)
|
58
80
|
def end_of_day
|
59
|
-
|
81
|
+
to_time_in_current_zone.end_of_day
|
60
82
|
end
|
61
83
|
|
62
84
|
def plus_with_duration(other) #:nodoc:
|
@@ -125,20 +147,20 @@ class Date
|
|
125
147
|
advance(:years => years)
|
126
148
|
end
|
127
149
|
|
128
|
-
#
|
129
|
-
def
|
150
|
+
# Shorthand for years_ago(1)
|
151
|
+
def prev_year
|
130
152
|
years_ago(1)
|
131
|
-
end
|
153
|
+
end unless method_defined?(:prev_year)
|
132
154
|
|
133
155
|
# Short-hand for years_since(1)
|
134
156
|
def next_year
|
135
157
|
years_since(1)
|
136
158
|
end unless method_defined?(:next_year)
|
137
|
-
|
159
|
+
|
138
160
|
# Short-hand for months_ago(1)
|
139
|
-
def
|
161
|
+
def prev_month
|
140
162
|
months_ago(1)
|
141
|
-
end
|
163
|
+
end unless method_defined?(:prev_month)
|
142
164
|
|
143
165
|
# Short-hand for months_since(1)
|
144
166
|
def next_month
|
@@ -160,6 +182,7 @@ class Date
|
|
160
182
|
result = self + days_to_sunday.days
|
161
183
|
self.acts_like?(:time) ? result.end_of_day : result
|
162
184
|
end
|
185
|
+
alias :sunday :end_of_week
|
163
186
|
alias :at_end_of_week :end_of_week
|
164
187
|
|
165
188
|
# Returns a new Date/DateTime representing the start of the given day in next week (default is Monday).
|
@@ -1,6 +1,6 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'active_support/inflector'
|
2
|
-
require 'active_support/core_ext/
|
3
|
-
require 'active_support/core_ext/date_time/conversions'
|
3
|
+
require 'active_support/core_ext/date/zones'
|
4
4
|
|
5
5
|
class Date
|
6
6
|
DATE_FORMATS = {
|
@@ -13,10 +13,10 @@ class Date
|
|
13
13
|
}
|
14
14
|
|
15
15
|
# Ruby 1.9 has Date#to_time which converts to localtime only.
|
16
|
-
remove_method :to_time if
|
16
|
+
remove_method :to_time if method_defined?(:to_time)
|
17
17
|
|
18
18
|
# Ruby 1.9 has Date#xmlschema which converts to a string without the time component.
|
19
|
-
remove_method :xmlschema if
|
19
|
+
remove_method :xmlschema if method_defined?(:xmlschema)
|
20
20
|
|
21
21
|
# Convert to a formatted string. See DATE_FORMATS for predefined formats.
|
22
22
|
#
|
@@ -94,6 +94,6 @@ class Date
|
|
94
94
|
end if RUBY_VERSION < '1.9'
|
95
95
|
|
96
96
|
def xmlschema
|
97
|
-
|
97
|
+
to_time_in_current_zone.xmlschema
|
98
98
|
end
|
99
99
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'active_support/core_ext/time/zones'
|
3
|
+
|
4
|
+
class Date
|
5
|
+
# Converts Date to a TimeWithZone in the current zone if Time.zone_default is set,
|
6
|
+
# otherwise converts Date to a Time via Date#to_time
|
7
|
+
def to_time_in_current_zone
|
8
|
+
if ::Time.zone_default
|
9
|
+
::Time.zone.local(year, month, day)
|
10
|
+
else
|
11
|
+
to_time
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
+
require 'active_support/core_ext/time/conversions'
|
3
|
+
require 'active_support/core_ext/date_time/calculations'
|
4
|
+
require 'active_support/values/time_zone'
|
2
5
|
|
3
6
|
class DateTime
|
4
7
|
# Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
|
@@ -58,7 +61,7 @@ class DateTime
|
|
58
61
|
# Converts self to a Ruby Date object; time portion is discarded
|
59
62
|
def to_date
|
60
63
|
::Date.new(year, month, day)
|
61
|
-
end unless
|
64
|
+
end unless instance_methods(false).include?(:to_date)
|
62
65
|
|
63
66
|
# Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
|
64
67
|
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
|
@@ -69,16 +72,32 @@ class DateTime
|
|
69
72
|
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
|
70
73
|
def to_datetime
|
71
74
|
self
|
72
|
-
end unless
|
75
|
+
end unless instance_methods(false).include?(:to_datetime)
|
76
|
+
|
77
|
+
def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
|
78
|
+
offset = utc_or_local.to_sym == :local ? local_offset : 0
|
79
|
+
civil(year, month, day, hour, min, sec, offset)
|
80
|
+
end
|
73
81
|
|
74
82
|
# Converts datetime to an appropriate format for use in XML
|
75
83
|
def xmlschema
|
76
84
|
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
77
|
-
end unless
|
85
|
+
end unless instance_methods(false).include?(:xmlschema)
|
78
86
|
|
79
87
|
# Converts self to a floating-point number of seconds since the Unix epoch
|
80
88
|
def to_f
|
81
|
-
|
82
|
-
|
89
|
+
seconds_since_unix_epoch.to_f
|
90
|
+
end
|
91
|
+
|
92
|
+
# Converts self to an integer number of seconds since the Unix epoch
|
93
|
+
def to_i
|
94
|
+
seconds_since_unix_epoch.to_i
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def seconds_since_unix_epoch
|
100
|
+
seconds_per_day = 86_400
|
101
|
+
(self - ::DateTime.civil(1970)) * seconds_per_day
|
83
102
|
end
|
84
103
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/time/zones'
|
2
|
+
|
1
3
|
class DateTime
|
2
4
|
# Returns the simultaneous time in <tt>Time.zone</tt>.
|
3
5
|
#
|
@@ -12,6 +14,8 @@ class DateTime
|
|
12
14
|
#
|
13
15
|
# DateTime.new(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
|
14
16
|
def in_time_zone(zone = ::Time.zone)
|
17
|
+
return self unless zone
|
18
|
+
|
15
19
|
ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
|
16
20
|
end
|
17
21
|
end
|
@@ -101,15 +101,11 @@ module Enumerable
|
|
101
101
|
size = block_given? ? select(&block).size : self.size
|
102
102
|
size > 1
|
103
103
|
end
|
104
|
-
|
105
|
-
# Returns true if
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# This is a builtin method in Ruby 1.8.7 and later.
|
110
|
-
def none?(&block)
|
111
|
-
!any?(&block)
|
112
|
-
end unless [].respond_to?(:none?)
|
104
|
+
|
105
|
+
# The negative of the Enumerable#include?. Returns true if the collection does not include the object.
|
106
|
+
def exclude?(object)
|
107
|
+
!include?(object)
|
108
|
+
end
|
113
109
|
end
|
114
110
|
|
115
111
|
class Range #:nodoc:
|
@@ -1,50 +1,3 @@
|
|
1
1
|
module ActiveSupport
|
2
2
|
FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError
|
3
3
|
end
|
4
|
-
|
5
|
-
# TODO: Turn all this into using the BacktraceCleaner.
|
6
|
-
class Exception # :nodoc:
|
7
|
-
# Clean the paths contained in the message.
|
8
|
-
def self.clean_paths(string)
|
9
|
-
require 'pathname' unless defined? Pathname
|
10
|
-
string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
|
11
|
-
Pathname.new(path).cleanpath
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def clean_message
|
16
|
-
Exception.clean_paths(message)
|
17
|
-
end
|
18
|
-
|
19
|
-
TraceSubstitutions = []
|
20
|
-
FrameworkStart = /action_controller\/dispatcher\.rb/.freeze
|
21
|
-
FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze
|
22
|
-
|
23
|
-
def clean_backtrace
|
24
|
-
backtrace.collect do |line|
|
25
|
-
substituted = TraceSubstitutions.inject(line) do |result, (regexp, sub)|
|
26
|
-
result.gsub regexp, sub
|
27
|
-
end
|
28
|
-
Exception.clean_paths(substituted)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def application_backtrace
|
33
|
-
before_framework_frame = nil
|
34
|
-
before_application_frame = true
|
35
|
-
|
36
|
-
trace = clean_backtrace.reject do |line|
|
37
|
-
before_framework_frame ||= (line =~ FrameworkStart)
|
38
|
-
non_app_frame = (line =~ FrameworkRegexp)
|
39
|
-
before_application_frame = false unless non_app_frame
|
40
|
-
before_framework_frame || (non_app_frame && !before_application_frame)
|
41
|
-
end
|
42
|
-
|
43
|
-
# If we didn't find any application frames, return an empty app trace.
|
44
|
-
before_application_frame ? [] : trace
|
45
|
-
end
|
46
|
-
|
47
|
-
def framework_backtrace
|
48
|
-
clean_backtrace.grep FrameworkRegexp
|
49
|
-
end
|
50
|
-
end
|
@@ -9,11 +9,12 @@ class File
|
|
9
9
|
# If your temp directory is not on the same filesystem as the file you're
|
10
10
|
# trying to write, you can provide a different temporary directory.
|
11
11
|
#
|
12
|
-
# File.atomic_write("/data/something.important", "/data/tmp") do |
|
12
|
+
# File.atomic_write("/data/something.important", "/data/tmp") do |file|
|
13
13
|
# file.write("hello")
|
14
14
|
# end
|
15
15
|
def self.atomic_write(file_name, temp_dir = Dir.tmpdir)
|
16
16
|
require 'tempfile' unless defined?(Tempfile)
|
17
|
+
require 'fileutils' unless defined?(FileUtils)
|
17
18
|
|
18
19
|
temp_file = Tempfile.new(basename(file_name), temp_dir)
|
19
20
|
yield temp_file
|
@@ -31,7 +32,7 @@ class File
|
|
31
32
|
end
|
32
33
|
|
33
34
|
# Overwrite original file with temp file
|
34
|
-
|
35
|
+
FileUtils.mv(temp_file.path, file_name)
|
35
36
|
|
36
37
|
# Set correct permissions on new file
|
37
38
|
chown(old_stat.uid, old_stat.gid, file_name)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class Float
|
2
|
-
|
2
|
+
alias precisionless_round round
|
3
|
+
private :precisionless_round
|
3
4
|
|
4
5
|
# Rounds the float with the specified precision.
|
5
6
|
#
|
@@ -12,7 +13,7 @@ class Float
|
|
12
13
|
magnitude = 10.0 ** precision
|
13
14
|
(self * magnitude).round / magnitude
|
14
15
|
else
|
15
|
-
|
16
|
+
precisionless_round
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -1,148 +1,76 @@
|
|
1
|
+
require 'active_support/xml_mini'
|
1
2
|
require 'active_support/time'
|
2
|
-
require 'active_support/core_ext/
|
3
|
-
require 'active_support/core_ext/array/conversions'
|
3
|
+
require 'active_support/core_ext/array/wrap'
|
4
4
|
require 'active_support/core_ext/hash/reverse_merge'
|
5
|
+
require 'active_support/core_ext/object/blank'
|
6
|
+
require 'active_support/core_ext/string/inflections'
|
5
7
|
|
6
8
|
class Hash
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
"date" => Proc.new { |date| date.to_s(:db) },
|
37
|
-
"datetime" => Proc.new { |time| time.xmlschema },
|
38
|
-
"binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) },
|
39
|
-
"yaml" => Proc.new { |yaml| yaml.to_yaml }
|
40
|
-
} unless defined?(XML_FORMATTING)
|
41
|
-
|
42
|
-
# TODO: use Time.xmlschema instead of Time.parse;
|
43
|
-
# use regexp instead of Date.parse
|
44
|
-
unless defined?(XML_PARSING)
|
45
|
-
XML_PARSING = {
|
46
|
-
"symbol" => Proc.new { |symbol| symbol.to_sym },
|
47
|
-
"date" => Proc.new { |date| ::Date.parse(date) },
|
48
|
-
"datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc },
|
49
|
-
"integer" => Proc.new { |integer| integer.to_i },
|
50
|
-
"float" => Proc.new { |float| float.to_f },
|
51
|
-
"decimal" => Proc.new { |number| BigDecimal(number) },
|
52
|
-
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
|
53
|
-
"string" => Proc.new { |string| string.to_s },
|
54
|
-
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
|
55
|
-
"base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
|
56
|
-
"file" => Proc.new do |file, entity|
|
57
|
-
f = StringIO.new(ActiveSupport::Base64.decode64(file))
|
58
|
-
f.extend(FileLike)
|
59
|
-
f.original_filename = entity['name']
|
60
|
-
f.content_type = entity['content_type']
|
61
|
-
f
|
62
|
-
end
|
63
|
-
}
|
64
|
-
|
65
|
-
XML_PARSING.update(
|
66
|
-
"double" => XML_PARSING["float"],
|
67
|
-
"dateTime" => XML_PARSING["datetime"]
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be
|
72
|
-
# passed to enclose the param names (see example below).
|
9
|
+
# Returns a string containing an XML representation of its receiver:
|
10
|
+
#
|
11
|
+
# {"foo" => 1, "bar" => 2}.to_xml
|
12
|
+
# # =>
|
13
|
+
# # <?xml version="1.0" encoding="UTF-8"?>
|
14
|
+
# # <hash>
|
15
|
+
# # <foo type="integer">1</foo>
|
16
|
+
# # <bar type="integer">2</bar>
|
17
|
+
# # </hash>
|
18
|
+
#
|
19
|
+
# To do so, the method loops over the pairs and builds nodes that depend on
|
20
|
+
# the _values_. Given a pair +key+, +value+:
|
21
|
+
#
|
22
|
+
# * If +value+ is a hash there's a recursive call with +key+ as <tt>:root</tt>.
|
23
|
+
#
|
24
|
+
# * If +value+ is an array there's a recursive call with +key+ as <tt>:root</tt>,
|
25
|
+
# and +key+ singularized as <tt>:children</tt>.
|
26
|
+
#
|
27
|
+
# * If +value+ is a callable object it must expect one or two arguments. Depending
|
28
|
+
# on the arity, the callable is invoked with the +options+ hash as first argument
|
29
|
+
# with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. Its
|
30
|
+
# return value becomes a new node.
|
31
|
+
#
|
32
|
+
# * If +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.
|
33
|
+
#
|
34
|
+
# * Otherwise, a node with +key+ as tag is created with a string representation of
|
35
|
+
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
|
36
|
+
# Unless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is
|
37
|
+
# added as well according to the following mapping:
|
73
38
|
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
39
|
+
# XML_TYPE_NAMES = {
|
40
|
+
# "Symbol" => "symbol",
|
41
|
+
# "Fixnum" => "integer",
|
42
|
+
# "Bignum" => "integer",
|
43
|
+
# "BigDecimal" => "decimal",
|
44
|
+
# "Float" => "float",
|
45
|
+
# "TrueClass" => "boolean",
|
46
|
+
# "FalseClass" => "boolean",
|
47
|
+
# "Date" => "date",
|
48
|
+
# "DateTime" => "datetime",
|
49
|
+
# "Time" => "datetime"
|
50
|
+
# }
|
51
|
+
#
|
52
|
+
# By default the root node is "hash", but that's configurable via the <tt>:root</tt> option.
|
53
|
+
#
|
54
|
+
# The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can
|
55
|
+
# configure your own builder with the <tt>:builder</tt> option. The method also accepts
|
56
|
+
# options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
|
86
57
|
def to_xml(options = {})
|
87
|
-
require 'builder' unless defined?(Builder)
|
58
|
+
require 'active_support/builder' unless defined?(Builder)
|
88
59
|
|
89
60
|
options = options.dup
|
90
|
-
options[:indent]
|
91
|
-
options
|
92
|
-
|
93
|
-
options[:builder].instruct! unless options.delete(:skip_instruct)
|
94
|
-
root = rename_key(options[:root].to_s, options)
|
61
|
+
options[:indent] ||= 2
|
62
|
+
options[:root] ||= "hash"
|
63
|
+
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
95
64
|
|
96
|
-
options[:builder]
|
97
|
-
|
98
|
-
case value
|
99
|
-
when ::Hash
|
100
|
-
value.to_xml(options.merge({ :root => key, :skip_instruct => true }))
|
101
|
-
when ::Array
|
102
|
-
value.to_xml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true}))
|
103
|
-
when ::Method, ::Proc
|
104
|
-
# If the Method or Proc takes two arguments, then
|
105
|
-
# pass the suggested child element name. This is
|
106
|
-
# used if the Method or Proc will be operating over
|
107
|
-
# multiple records and needs to create an containing
|
108
|
-
# element that will contain the objects being
|
109
|
-
# serialized.
|
110
|
-
if 1 == value.arity
|
111
|
-
value.call(options.merge({ :root => key, :skip_instruct => true }))
|
112
|
-
else
|
113
|
-
value.call(options.merge({ :root => key, :skip_instruct => true }), key.to_s.singularize)
|
114
|
-
end
|
115
|
-
else
|
116
|
-
if value.respond_to?(:to_xml)
|
117
|
-
value.to_xml(options.merge({ :root => key, :skip_instruct => true }))
|
118
|
-
else
|
119
|
-
type_name = XML_TYPE_NAMES[value.class.name]
|
65
|
+
builder = options[:builder]
|
66
|
+
builder.instruct! unless options.delete(:skip_instruct)
|
120
67
|
|
121
|
-
|
68
|
+
root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
|
122
69
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
options[:builder].tag!(key,
|
129
|
-
XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
|
130
|
-
attributes
|
131
|
-
)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
yield options[:builder] if block_given?
|
70
|
+
builder.__send__(:method_missing, root) do
|
71
|
+
each { |key, value| ActiveSupport::XmlMini.to_tag(key, value, options) }
|
72
|
+
yield builder if block_given?
|
137
73
|
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
def rename_key(key, options = {})
|
142
|
-
camelize = options.has_key?(:camelize) && options[:camelize]
|
143
|
-
dasherize = !options.has_key?(:dasherize) || options[:dasherize]
|
144
|
-
key = key.camelize if camelize
|
145
|
-
dasherize ? key.dasherize : key
|
146
74
|
end
|
147
75
|
|
148
76
|
class << self
|
@@ -155,7 +83,7 @@ class Hash
|
|
155
83
|
case value.class.to_s
|
156
84
|
when 'Hash'
|
157
85
|
if value['type'] == 'array'
|
158
|
-
|
86
|
+
_, entries = Array.wrap(value.detect { |k,v| k != 'type' })
|
159
87
|
if entries.nil? || (c = value['__content__'] && c.blank?)
|
160
88
|
[]
|
161
89
|
else
|
@@ -170,12 +98,8 @@ class Hash
|
|
170
98
|
end
|
171
99
|
elsif value.has_key?("__content__")
|
172
100
|
content = value["__content__"]
|
173
|
-
if parser =
|
174
|
-
|
175
|
-
XML_PARSING[value["type"]].call(content, value)
|
176
|
-
else
|
177
|
-
XML_PARSING[value["type"]].call(content)
|
178
|
-
end
|
101
|
+
if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
|
102
|
+
parser.arity == 1 ? parser.call(content) : parser.call(content, value)
|
179
103
|
else
|
180
104
|
content
|
181
105
|
end
|
@@ -201,11 +125,7 @@ class Hash
|
|
201
125
|
end
|
202
126
|
when 'Array'
|
203
127
|
value.map! { |i| typecast_xml_value(i) }
|
204
|
-
|
205
|
-
when 0 then nil
|
206
|
-
when 1 then value.first
|
207
|
-
else value
|
208
|
-
end
|
128
|
+
value.length > 1 ? value : value.first
|
209
129
|
when 'String'
|
210
130
|
value
|
211
131
|
else
|