activesupport_csi 2.3.5.p6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1330 -0
- data/README +43 -0
- data/lib/active_support/all.rb +8 -0
- data/lib/active_support/backtrace_cleaner.rb +72 -0
- data/lib/active_support/base64.rb +33 -0
- data/lib/active_support/basic_object.rb +24 -0
- data/lib/active_support/buffered_logger.rb +127 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
- data/lib/active_support/cache/drb_store.rb +14 -0
- data/lib/active_support/cache/file_store.rb +72 -0
- data/lib/active_support/cache/mem_cache_store.rb +143 -0
- data/lib/active_support/cache/memory_store.rb +52 -0
- data/lib/active_support/cache/strategy/local_cache.rb +104 -0
- data/lib/active_support/cache/synchronized_memory_store.rb +47 -0
- data/lib/active_support/cache.rb +248 -0
- data/lib/active_support/callbacks.rb +279 -0
- data/lib/active_support/core_ext/array/access.rb +53 -0
- data/lib/active_support/core_ext/array/conversions.rb +197 -0
- data/lib/active_support/core_ext/array/extract_options.rb +20 -0
- data/lib/active_support/core_ext/array/grouping.rb +106 -0
- data/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/lib/active_support/core_ext/array/wrapper.rb +24 -0
- data/lib/active_support/core_ext/array.rb +15 -0
- data/lib/active_support/core_ext/base64/encoding.rb +16 -0
- data/lib/active_support/core_ext/base64.rb +4 -0
- data/lib/active_support/core_ext/benchmark.rb +19 -0
- data/lib/active_support/core_ext/bigdecimal/conversions.rb +37 -0
- data/lib/active_support/core_ext/bigdecimal.rb +6 -0
- data/lib/active_support/core_ext/blank.rb +2 -0
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +23 -0
- data/lib/active_support/core_ext/cgi.rb +5 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +54 -0
- data/lib/active_support/core_ext/class/delegating_attributes.rb +47 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/lib/active_support/core_ext/class/removal.rb +50 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/behavior.rb +42 -0
- data/lib/active_support/core_ext/date/calculations.rb +231 -0
- data/lib/active_support/core_ext/date/conversions.rb +107 -0
- data/lib/active_support/core_ext/date.rb +10 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +126 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +96 -0
- data/lib/active_support/core_ext/date_time.rb +12 -0
- data/lib/active_support/core_ext/duplicable.rb +43 -0
- data/lib/active_support/core_ext/enumerable.rb +114 -0
- data/lib/active_support/core_ext/exception.rb +45 -0
- data/lib/active_support/core_ext/file/atomic.rb +46 -0
- data/lib/active_support/core_ext/file.rb +5 -0
- data/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/lib/active_support/core_ext/float/time.rb +27 -0
- data/lib/active_support/core_ext/float.rb +7 -0
- data/lib/active_support/core_ext/hash/conversions.rb +264 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
- data/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/lib/active_support/core_ext/hash/except.rb +25 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +143 -0
- data/lib/active_support/core_ext/hash/keys.rb +52 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
- data/lib/active_support/core_ext/hash/slice.rb +40 -0
- data/lib/active_support/core_ext/hash.rb +14 -0
- data/lib/active_support/core_ext/integer/even_odd.rb +29 -0
- data/lib/active_support/core_ext/integer/inflections.rb +20 -0
- data/lib/active_support/core_ext/integer/time.rb +45 -0
- data/lib/active_support/core_ext/integer.rb +9 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +16 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +59 -0
- data/lib/active_support/core_ext/kernel/requires.rb +24 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/load_error.rb +38 -0
- data/lib/active_support/core_ext/logger.rb +145 -0
- data/lib/active_support/core_ext/module/aliasing.rb +74 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +32 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +60 -0
- data/lib/active_support/core_ext/module/delegation.rb +135 -0
- data/lib/active_support/core_ext/module/inclusion.rb +30 -0
- data/lib/active_support/core_ext/module/introspection.rb +90 -0
- data/lib/active_support/core_ext/module/loading.rb +23 -0
- data/lib/active_support/core_ext/module/model_naming.rb +25 -0
- data/lib/active_support/core_ext/module/synchronization.rb +39 -0
- data/lib/active_support/core_ext/module.rb +23 -0
- data/lib/active_support/core_ext/name_error.rb +19 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +50 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +19 -0
- data/lib/active_support/core_ext/numeric/time.rb +81 -0
- data/lib/active_support/core_ext/numeric.rb +9 -0
- data/lib/active_support/core_ext/object/blank.rb +58 -0
- data/lib/active_support/core_ext/object/conversions.rb +15 -0
- data/lib/active_support/core_ext/object/extending.rb +80 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +74 -0
- data/lib/active_support/core_ext/object/metaclass.rb +13 -0
- data/lib/active_support/core_ext/object/misc.rb +90 -0
- data/lib/active_support/core_ext/object.rb +6 -0
- data/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
- data/lib/active_support/core_ext/pathname.rb +7 -0
- data/lib/active_support/core_ext/proc.rb +12 -0
- data/lib/active_support/core_ext/process/daemon.rb +25 -0
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/range/blockless_step.rb +32 -0
- data/lib/active_support/core_ext/range/conversions.rb +27 -0
- data/lib/active_support/core_ext/range/include_range.rb +30 -0
- data/lib/active_support/core_ext/range/overlaps.rb +15 -0
- data/lib/active_support/core_ext/range.rb +11 -0
- data/lib/active_support/core_ext/rexml.rb +41 -0
- data/lib/active_support/core_ext/string/access.rb +106 -0
- data/lib/active_support/core_ext/string/behavior.rb +13 -0
- data/lib/active_support/core_ext/string/bytesize.rb +5 -0
- data/lib/active_support/core_ext/string/conversions.rb +28 -0
- data/lib/active_support/core_ext/string/filters.rb +26 -0
- data/lib/active_support/core_ext/string/inflections.rb +167 -0
- data/lib/active_support/core_ext/string/iterators.rb +23 -0
- data/lib/active_support/core_ext/string/multibyte.rb +81 -0
- data/lib/active_support/core_ext/string/output_safety.rb +48 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +35 -0
- data/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/lib/active_support/core_ext/string.rb +25 -0
- data/lib/active_support/core_ext/symbol.rb +14 -0
- data/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/lib/active_support/core_ext/time/calculations.rb +304 -0
- data/lib/active_support/core_ext/time/conversions.rb +90 -0
- data/lib/active_support/core_ext/time/zones.rb +86 -0
- data/lib/active_support/core_ext/time.rb +42 -0
- data/lib/active_support/core_ext/try.rb +36 -0
- data/lib/active_support/core_ext/uri.rb +16 -0
- data/lib/active_support/core_ext.rb +8 -0
- data/lib/active_support/dependencies.rb +625 -0
- data/lib/active_support/deprecation.rb +196 -0
- data/lib/active_support/duration.rb +100 -0
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/inflections.rb +56 -0
- data/lib/active_support/inflector.rb +406 -0
- data/lib/active_support/json/backends/jsongem.rb +37 -0
- data/lib/active_support/json/backends/okjson.rb +644 -0
- data/lib/active_support/json/backends/yaml.rb +20 -0
- data/lib/active_support/json/decoding.rb +50 -0
- data/lib/active_support/json/encoders/date.rb +22 -0
- data/lib/active_support/json/encoders/date_time.rb +22 -0
- data/lib/active_support/json/encoders/enumerable.rb +17 -0
- data/lib/active_support/json/encoders/false_class.rb +7 -0
- data/lib/active_support/json/encoders/hash.rb +56 -0
- data/lib/active_support/json/encoders/nil_class.rb +7 -0
- data/lib/active_support/json/encoders/numeric.rb +21 -0
- data/lib/active_support/json/encoders/object.rb +10 -0
- data/lib/active_support/json/encoders/regexp.rb +9 -0
- data/lib/active_support/json/encoders/string.rb +9 -0
- data/lib/active_support/json/encoders/symbol.rb +5 -0
- data/lib/active_support/json/encoders/time.rb +22 -0
- data/lib/active_support/json/encoders/true_class.rb +7 -0
- data/lib/active_support/json/encoding.rb +102 -0
- data/lib/active_support/json/variable.rb +10 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/locale/en.yml +33 -0
- data/lib/active_support/memoizable.rb +100 -0
- data/lib/active_support/message_encryptor.rb +70 -0
- data/lib/active_support/message_verifier.rb +79 -0
- data/lib/active_support/multibyte/chars.rb +707 -0
- data/lib/active_support/multibyte/exceptions.rb +8 -0
- data/lib/active_support/multibyte/unicode_database.rb +71 -0
- data/lib/active_support/multibyte/utils.rb +61 -0
- data/lib/active_support/multibyte.rb +57 -0
- data/lib/active_support/option_merger.rb +23 -0
- data/lib/active_support/ordered_hash.rb +141 -0
- data/lib/active_support/ordered_options.rb +19 -0
- data/lib/active_support/rescuable.rb +108 -0
- data/lib/active_support/secure_random.rb +199 -0
- data/lib/active_support/string_inquirer.rb +21 -0
- data/lib/active_support/test_case.rb +40 -0
- data/lib/active_support/testing/assertions.rb +65 -0
- data/lib/active_support/testing/declarative.rb +21 -0
- data/lib/active_support/testing/default.rb +9 -0
- data/lib/active_support/testing/deprecation.rb +57 -0
- data/lib/active_support/testing/performance.rb +452 -0
- data/lib/active_support/testing/setup_and_teardown.rb +91 -0
- data/lib/active_support/time_with_zone.rb +335 -0
- data/lib/active_support/values/time_zone.rb +404 -0
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +20 -0
- data/lib/active_support/vendor/i18n-0.1.3/README.textile +20 -0
- data/lib/active_support/vendor/i18n-0.1.3/Rakefile +5 -0
- data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +27 -0
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +214 -0
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +53 -0
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +199 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +5 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +99 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +124 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +1 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +3 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +567 -0
- data/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb +1107 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +228 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +55 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +219 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +40 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +283 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +136 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +204 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +274 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +194 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +139 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +144 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +131 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +282 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +74 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +205 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +196 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +67 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +73 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +24 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +34 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +59 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +121 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +270 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +29 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +193 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +37 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +16 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +188 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +197 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +276 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +218 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +168 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +268 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +211 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +176 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +215 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +173 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +172 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +183 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +212 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +202 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +52 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +51 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +44 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +98 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +56 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +292 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +508 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +56 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +40 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +94 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +198 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +129 -0
- data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +33 -0
- data/lib/active_support/vendor.rb +28 -0
- data/lib/active_support/version.rb +9 -0
- data/lib/active_support/whiny_nil.rb +64 -0
- data/lib/active_support/xml_mini/jdom.rb +162 -0
- data/lib/active_support/xml_mini/libxml.rb +133 -0
- data/lib/active_support/xml_mini/nokogiri.rb +69 -0
- data/lib/active_support/xml_mini/rexml.rb +108 -0
- data/lib/active_support/xml_mini.rb +31 -0
- data/lib/active_support.rb +59 -0
- data/lib/activesupport.rb +2 -0
- metadata +418 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Integer #:nodoc:
|
4
|
+
# Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
|
5
|
+
#
|
6
|
+
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
|
7
|
+
# as well as adding or subtracting their results from a Time object. For example:
|
8
|
+
#
|
9
|
+
# # equivalent to Time.now.advance(:months => 1)
|
10
|
+
# 1.month.from_now
|
11
|
+
#
|
12
|
+
# # equivalent to Time.now.advance(:years => 2)
|
13
|
+
# 2.years.from_now
|
14
|
+
#
|
15
|
+
# # equivalent to Time.now.advance(:months => 4, :years => 5)
|
16
|
+
# (4.months + 5.years).from_now
|
17
|
+
#
|
18
|
+
# While these methods provide precise calculation when used as in the examples above, care
|
19
|
+
# should be taken to note that this is not true if the result of `months', `years', etc is
|
20
|
+
# converted before use:
|
21
|
+
#
|
22
|
+
# # equivalent to 30.days.to_i.from_now
|
23
|
+
# 1.month.to_i.from_now
|
24
|
+
#
|
25
|
+
# # equivalent to 365.25.days.to_f.from_now
|
26
|
+
# 1.year.to_f.from_now
|
27
|
+
#
|
28
|
+
# In such cases, Ruby's core
|
29
|
+
# Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and
|
30
|
+
# Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision
|
31
|
+
# date and time arithmetic
|
32
|
+
module Time
|
33
|
+
def months
|
34
|
+
ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
|
35
|
+
end
|
36
|
+
alias :month :months
|
37
|
+
|
38
|
+
def years
|
39
|
+
ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
|
40
|
+
end
|
41
|
+
alias :year :years
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_support/core_ext/integer/even_odd'
|
2
|
+
require 'active_support/core_ext/integer/inflections'
|
3
|
+
require 'active_support/core_ext/integer/time'
|
4
|
+
|
5
|
+
class Integer #:nodoc:
|
6
|
+
include ActiveSupport::CoreExtensions::Integer::EvenOdd
|
7
|
+
include ActiveSupport::CoreExtensions::Integer::Inflections
|
8
|
+
include ActiveSupport::CoreExtensions::Integer::Time
|
9
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Object
|
2
|
+
# Makes backticks behave (somewhat more) similarly on all platforms.
|
3
|
+
# On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the
|
4
|
+
# spawned shell prints a message to stderr and sets $?. We emulate
|
5
|
+
# Unix on the former but not the latter.
|
6
|
+
def `(command) #:nodoc:
|
7
|
+
super
|
8
|
+
rescue Errno::ENOENT => e
|
9
|
+
STDERR.puts "#$0: #{e}"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kernel
|
2
|
+
unless respond_to?(:debugger)
|
3
|
+
# Starts a debugging session if ruby-debug has been loaded (call script/server --debugger to do load it).
|
4
|
+
def debugger
|
5
|
+
message = "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n"
|
6
|
+
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
undef :breakpoint if respond_to?(:breakpoint)
|
11
|
+
def breakpoint
|
12
|
+
message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
|
13
|
+
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
|
14
|
+
debugger
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Kernel
|
2
|
+
# Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
|
3
|
+
#
|
4
|
+
# silence_warnings do
|
5
|
+
# value = noisy_call # no warning voiced
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# noisy_call # warning voiced
|
9
|
+
def silence_warnings
|
10
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
$VERBOSE = old_verbose
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.
|
17
|
+
def enable_warnings
|
18
|
+
old_verbose, $VERBOSE = $VERBOSE, true
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
$VERBOSE = old_verbose
|
22
|
+
end
|
23
|
+
|
24
|
+
# For compatibility
|
25
|
+
def silence_stderr #:nodoc:
|
26
|
+
silence_stream(STDERR) { yield }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Silences any stream for the duration of the block.
|
30
|
+
#
|
31
|
+
# silence_stream(STDOUT) do
|
32
|
+
# puts 'This will never be seen'
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# puts 'But this will'
|
36
|
+
def silence_stream(stream)
|
37
|
+
old_stream = stream.dup
|
38
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
39
|
+
stream.sync = true
|
40
|
+
yield
|
41
|
+
ensure
|
42
|
+
stream.reopen(old_stream)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Blocks and ignores any exception passed as argument if raised within the block.
|
46
|
+
#
|
47
|
+
# suppress(ZeroDivisionError) do
|
48
|
+
# 1/0
|
49
|
+
# puts "This code is NOT reached"
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# puts "This code gets executed and nothing related to ZeroDivisionError was seen"
|
53
|
+
def suppress(*exception_classes)
|
54
|
+
begin yield
|
55
|
+
rescue Exception => e
|
56
|
+
raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Kernel
|
2
|
+
# Require a library with fallback to RubyGems. Warnings during library
|
3
|
+
# loading are silenced to increase signal/noise for application warnings.
|
4
|
+
def require_library_or_gem(library_name)
|
5
|
+
silence_warnings do
|
6
|
+
begin
|
7
|
+
require library_name
|
8
|
+
rescue LoadError => cannot_require
|
9
|
+
# 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
|
10
|
+
begin
|
11
|
+
require 'rubygems'
|
12
|
+
rescue LoadError => rubygems_not_installed
|
13
|
+
raise cannot_require
|
14
|
+
end
|
15
|
+
# 2. Rubygems is installed and loaded. Try to load the library again
|
16
|
+
begin
|
17
|
+
require library_name
|
18
|
+
rescue LoadError => gem_not_installed
|
19
|
+
raise cannot_require
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class MissingSourceFile < LoadError #:nodoc:
|
2
|
+
attr_reader :path
|
3
|
+
def initialize(message, path)
|
4
|
+
super(message)
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def is_missing?(path)
|
9
|
+
path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_message(message)
|
13
|
+
REGEXPS.each do |regexp, capture|
|
14
|
+
match = regexp.match(message)
|
15
|
+
return MissingSourceFile.new(message, match[capture]) unless match.nil?
|
16
|
+
end
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
REGEXPS = [
|
21
|
+
[/^no such file to load -- (.+)$/i, 1],
|
22
|
+
[/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
|
23
|
+
[/^Missing API definition file in (.+)$/i, 1]
|
24
|
+
] unless defined?(REGEXPS)
|
25
|
+
end
|
26
|
+
|
27
|
+
module ActiveSupport #:nodoc:
|
28
|
+
module CoreExtensions #:nodoc:
|
29
|
+
module LoadErrorExtensions #:nodoc:
|
30
|
+
module LoadErrorClassMethods #:nodoc:
|
31
|
+
def new(*args)
|
32
|
+
(self == LoadError && MissingSourceFile.from_message(args.first)) || super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
::LoadError.extend(LoadErrorClassMethods)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Adds the 'around_level' method to Logger.
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
def self.define_around_helper(level)
|
5
|
+
module_eval <<-end_eval
|
6
|
+
def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block)
|
7
|
+
self.#{level}(before_message) # self.debug(before_message)
|
8
|
+
return_value = block.call(self) # return_value = block.call(self)
|
9
|
+
self.#{level}(after_message) # self.debug(after_message)
|
10
|
+
return return_value # return return_value
|
11
|
+
end # end
|
12
|
+
end_eval
|
13
|
+
end
|
14
|
+
[:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
|
15
|
+
end
|
16
|
+
|
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_formatter :formatter if method_defined?(:formatter)
|
68
|
+
# Get the current formatter. The default formatter is a SimpleFormatter which only
|
69
|
+
# displays the log message
|
70
|
+
def formatter
|
71
|
+
@formatter ||= SimpleFormatter.new
|
72
|
+
end
|
73
|
+
|
74
|
+
unless const_defined? :Formatter
|
75
|
+
class Formatter
|
76
|
+
Format = "%s, [%s#%d] %5s -- %s: %s\n"
|
77
|
+
|
78
|
+
attr_accessor :datetime_format
|
79
|
+
|
80
|
+
def initialize
|
81
|
+
@datetime_format = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def call(severity, time, progname, msg)
|
85
|
+
Format % [severity[0..0], format_datetime(time), $$, severity, progname,
|
86
|
+
msg2str(msg)]
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def format_datetime(time)
|
91
|
+
if @datetime_format.nil?
|
92
|
+
time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec
|
93
|
+
else
|
94
|
+
time.strftime(@datetime_format)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def msg2str(msg)
|
99
|
+
case msg
|
100
|
+
when ::String
|
101
|
+
msg
|
102
|
+
when ::Exception
|
103
|
+
"#{ msg.message } (#{ msg.class })\n" <<
|
104
|
+
(msg.backtrace || []).join("\n")
|
105
|
+
else
|
106
|
+
msg.inspect
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Simple formatter which only displays the message.
|
113
|
+
class SimpleFormatter < Logger::Formatter
|
114
|
+
# This method is invoked when a log event occurs
|
115
|
+
def call(severity, timestamp, progname, msg)
|
116
|
+
"#{String === msg ? msg : msg.inspect}\n"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
alias old_format_message format_message
|
122
|
+
|
123
|
+
# Ruby 1.8.3 transposed the msg and progname arguments to format_message.
|
124
|
+
# We can't test RUBY_VERSION because some distributions don't keep Ruby
|
125
|
+
# and its standard library in sync, leading to installations of Ruby 1.8.2
|
126
|
+
# with Logger from 1.8.3 and vice versa.
|
127
|
+
if method_defined?(:formatter=)
|
128
|
+
def format_message(severity, timestamp, progname, msg)
|
129
|
+
formatter.call(severity, timestamp, progname, msg)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
def format_message(severity, timestamp, msg, progname)
|
133
|
+
formatter.call(severity, timestamp, progname, msg)
|
134
|
+
end
|
135
|
+
|
136
|
+
attr_writer :formatter
|
137
|
+
public :formatter=
|
138
|
+
|
139
|
+
alias old_format_datetime format_datetime
|
140
|
+
def format_datetime(datetime) datetime end
|
141
|
+
|
142
|
+
alias old_msg2str msg2str
|
143
|
+
def msg2str(msg) msg end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module CoreExtensions
|
3
|
+
module Module
|
4
|
+
# Encapsulates the common pattern of:
|
5
|
+
#
|
6
|
+
# alias_method :foo_without_feature, :foo
|
7
|
+
# alias_method :foo, :foo_with_feature
|
8
|
+
#
|
9
|
+
# With this, you simply do:
|
10
|
+
#
|
11
|
+
# alias_method_chain :foo, :feature
|
12
|
+
#
|
13
|
+
# And both aliases are set up for you.
|
14
|
+
#
|
15
|
+
# Query and bang methods (foo?, foo!) keep the same punctuation:
|
16
|
+
#
|
17
|
+
# alias_method_chain :foo?, :feature
|
18
|
+
#
|
19
|
+
# is equivalent to
|
20
|
+
#
|
21
|
+
# alias_method :foo_without_feature?, :foo?
|
22
|
+
# alias_method :foo?, :foo_with_feature?
|
23
|
+
#
|
24
|
+
# so you can safely chain foo, foo?, and foo! with the same feature.
|
25
|
+
def alias_method_chain(target, feature)
|
26
|
+
# Strip out punctuation on predicates or bang methods since
|
27
|
+
# e.g. target?_without_feature is not a valid method name.
|
28
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
29
|
+
yield(aliased_target, punctuation) if block_given?
|
30
|
+
|
31
|
+
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
|
32
|
+
|
33
|
+
alias_method without_method, target
|
34
|
+
alias_method target, with_method
|
35
|
+
|
36
|
+
case
|
37
|
+
when public_method_defined?(without_method)
|
38
|
+
public target
|
39
|
+
when protected_method_defined?(without_method)
|
40
|
+
protected target
|
41
|
+
when private_method_defined?(without_method)
|
42
|
+
private target
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Allows you to make aliases for attributes, which includes
|
47
|
+
# getter, setter, and query methods.
|
48
|
+
#
|
49
|
+
# Example:
|
50
|
+
#
|
51
|
+
# class Content < ActiveRecord::Base
|
52
|
+
# # has a title attribute
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# class Email < Content
|
56
|
+
# alias_attribute :subject, :title
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# e = Email.find(1)
|
60
|
+
# e.title # => "Superstars"
|
61
|
+
# e.subject # => "Superstars"
|
62
|
+
# e.subject? # => true
|
63
|
+
# e.subject = "Megastars"
|
64
|
+
# e.title # => "Megastars"
|
65
|
+
def alias_attribute(new_name, old_name)
|
66
|
+
module_eval <<-STR, __FILE__, __LINE__+1
|
67
|
+
def #{new_name}; self.#{old_name}; end # def subject; self.title; end
|
68
|
+
def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end
|
69
|
+
def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end
|
70
|
+
STR
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
+
# some_person.age
|
11
|
+
# => 25
|
12
|
+
# some_person.age = 26
|
13
|
+
# some_person.age
|
14
|
+
# => 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 = nil, &block)
|
22
|
+
raise 'Default value or block required' unless !default.nil? || block
|
23
|
+
define_method(sym, block_given? ? block : Proc.new { default })
|
24
|
+
module_eval(<<-EVAL, __FILE__, __LINE__)
|
25
|
+
def #{sym}=(value) # def age=(value)
|
26
|
+
class << self; attr_reader :#{sym} end # class << self; attr_reader :age end
|
27
|
+
@#{sym} = value # @age = value
|
28
|
+
end # end
|
29
|
+
EVAL
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Module
|
2
|
+
# Declares an attribute reader backed by an internally-named instance variable.
|
3
|
+
def attr_internal_reader(*attrs)
|
4
|
+
attrs.each do |attr|
|
5
|
+
module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Declares an attribute writer backed by an internally-named instance variable.
|
10
|
+
def attr_internal_writer(*attrs)
|
11
|
+
attrs.each do |attr|
|
12
|
+
module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Declares an attribute reader and writer backed by an internally-named instance
|
17
|
+
# variable.
|
18
|
+
def attr_internal_accessor(*attrs)
|
19
|
+
attr_internal_reader(*attrs)
|
20
|
+
attr_internal_writer(*attrs)
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :attr_internal, :attr_internal_accessor
|
24
|
+
|
25
|
+
private
|
26
|
+
mattr_accessor :attr_internal_naming_format
|
27
|
+
self.attr_internal_naming_format = '@_%s'
|
28
|
+
|
29
|
+
def attr_internal_ivar_name(attr)
|
30
|
+
attr_internal_naming_format % attr
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "active_support/core_ext/array"
|
2
|
+
|
3
|
+
# Extends the module object with module and instance accessors for class attributes,
|
4
|
+
# just like the native attr* accessors for instance attributes.
|
5
|
+
#
|
6
|
+
# module AppConfiguration
|
7
|
+
# mattr_accessor :google_api_key
|
8
|
+
# self.google_api_key = "123456789"
|
9
|
+
#
|
10
|
+
# mattr_accessor :paypal_url
|
11
|
+
# self.paypal_url = "www.sandbox.paypal.com"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# AppConfiguration.google_api_key = "overriding the api key!"
|
15
|
+
class Module
|
16
|
+
def mattr_reader(*syms)
|
17
|
+
syms.each do |sym|
|
18
|
+
next if sym.is_a?(Hash)
|
19
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
20
|
+
unless defined? @@#{sym} # unless defined? @@pagination_options
|
21
|
+
@@#{sym} = nil # @@pagination_options = nil
|
22
|
+
end # end
|
23
|
+
#
|
24
|
+
def self.#{sym} # def self.pagination_options
|
25
|
+
@@#{sym} # @@pagination_options
|
26
|
+
end # end
|
27
|
+
#
|
28
|
+
def #{sym} # def pagination_options
|
29
|
+
@@#{sym} # @@pagination_options
|
30
|
+
end # end
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def mattr_writer(*syms)
|
36
|
+
options = syms.extract_options!
|
37
|
+
syms.each do |sym|
|
38
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
39
|
+
unless defined? @@#{sym} # unless defined? @@pagination_options
|
40
|
+
@@#{sym} = nil # @@pagination_options = nil
|
41
|
+
end # end
|
42
|
+
#
|
43
|
+
def self.#{sym}=(obj) # def self.pagination_options=(obj)
|
44
|
+
@@#{sym} = obj # @@pagination_options = obj
|
45
|
+
end # end
|
46
|
+
#
|
47
|
+
#{" #
|
48
|
+
def #{sym}=(obj) # def pagination_options=(obj)
|
49
|
+
@@#{sym} = obj # @@pagination_options = obj
|
50
|
+
end # end
|
51
|
+
" unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
|
52
|
+
EOS
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def mattr_accessor(*syms)
|
57
|
+
mattr_reader(*syms)
|
58
|
+
mattr_writer(*syms)
|
59
|
+
end
|
60
|
+
end
|