activesupport 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- data/CHANGELOG +183 -5
- data/lib/active_support.rb +6 -2
- data/lib/active_support/base64.rb +5 -0
- data/lib/active_support/basic_object.rb +23 -4
- data/lib/active_support/buffered_logger.rb +17 -3
- data/lib/active_support/cache.rb +145 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +15 -0
- data/lib/active_support/cache/drb_store.rb +15 -0
- data/lib/active_support/cache/file_store.rb +70 -0
- data/lib/active_support/cache/mem_cache_store.rb +100 -0
- data/lib/active_support/cache/memory_store.rb +38 -0
- data/lib/active_support/callbacks.rb +275 -0
- data/lib/active_support/core_ext/array/access.rb +2 -4
- data/lib/active_support/core_ext/array/conversions.rb +89 -5
- data/lib/active_support/core_ext/array/extract_options.rb +2 -1
- data/lib/active_support/core_ext/array/grouping.rb +3 -8
- data/lib/active_support/core_ext/array/random_access.rb +1 -1
- data/lib/active_support/core_ext/base64.rb +4 -0
- data/lib/active_support/core_ext/base64/encoding.rb +13 -0
- data/lib/active_support/core_ext/benchmark.rb +12 -0
- data/lib/active_support/core_ext/bigdecimal.rb +4 -0
- data/lib/active_support/core_ext/bigdecimal/conversions.rb +39 -4
- data/lib/active_support/core_ext/blank.rb +5 -2
- data/lib/active_support/core_ext/class/attribute_accessors.rb +7 -1
- data/lib/active_support/core_ext/class/delegating_attributes.rb +7 -1
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +1 -1
- data/lib/active_support/core_ext/class/removal.rb +26 -0
- data/lib/active_support/core_ext/date/calculations.rb +28 -1
- data/lib/active_support/core_ext/date/conversions.rb +1 -0
- data/lib/active_support/core_ext/date_time.rb +2 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +37 -2
- data/lib/active_support/core_ext/date_time/conversions.rb +27 -14
- data/lib/active_support/core_ext/enumerable.rb +16 -9
- data/lib/active_support/core_ext/exception.rb +8 -0
- data/lib/active_support/core_ext/file.rb +6 -6
- data/lib/active_support/core_ext/hash/conversions.rb +26 -8
- data/lib/active_support/core_ext/hash/indifferent_access.rb +35 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +4 -1
- data/lib/active_support/core_ext/integer/even_odd.rb +10 -5
- data/lib/active_support/core_ext/integer/inflections.rb +0 -1
- data/lib/active_support/core_ext/kernel/daemonizing.rb +2 -10
- data/lib/active_support/core_ext/kernel/reporting.rb +8 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -3
- data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -1
- data/lib/active_support/core_ext/module/delegation.rb +5 -3
- data/lib/active_support/core_ext/module/inclusion.rb +19 -0
- data/lib/active_support/core_ext/module/introspection.rb +50 -16
- data/lib/active_support/core_ext/module/loading.rb +10 -0
- data/lib/active_support/core_ext/numeric.rb +3 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +19 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +52 -0
- data/lib/active_support/core_ext/object/misc.rb +1 -1
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/process/daemon.rb +25 -0
- data/lib/active_support/core_ext/range/conversions.rb +5 -1
- data/lib/active_support/core_ext/range/include_range.rb +8 -0
- data/lib/active_support/core_ext/range/overlaps.rb +3 -0
- data/lib/active_support/core_ext/string.rb +5 -10
- data/lib/active_support/core_ext/string/access.rb +72 -48
- data/lib/active_support/core_ext/string/conversions.rb +4 -4
- data/lib/active_support/core_ext/string/filters.rb +26 -0
- data/lib/active_support/core_ext/string/inflections.rb +56 -64
- data/lib/active_support/core_ext/string/iterators.rb +4 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +12 -4
- data/lib/active_support/core_ext/string/unicode.rb +14 -7
- data/lib/active_support/core_ext/symbol.rb +1 -1
- data/lib/active_support/core_ext/time.rb +2 -0
- data/lib/active_support/core_ext/time/calculations.rb +75 -23
- data/lib/active_support/core_ext/time/conversions.rb +22 -35
- data/lib/active_support/core_ext/time/zones.rb +86 -0
- data/lib/active_support/dependencies.rb +92 -80
- data/lib/active_support/deprecation.rb +2 -16
- data/lib/active_support/duration.rb +4 -4
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/inflector.rb +92 -69
- data/lib/active_support/json.rb +17 -25
- data/lib/active_support/json/decoding.rb +1 -1
- data/lib/active_support/json/encoders/date.rb +11 -2
- data/lib/active_support/json/encoders/date_time.rb +11 -2
- data/lib/active_support/json/encoders/enumerable.rb +2 -2
- data/lib/active_support/json/encoders/hash.rb +3 -6
- data/lib/active_support/json/encoders/object.rb +1 -1
- data/lib/active_support/json/encoders/string.rb +8 -2
- data/lib/active_support/json/encoders/time.rb +11 -2
- data/lib/active_support/json/encoding.rb +0 -1
- data/lib/active_support/multibyte/chars.rb +8 -6
- data/lib/active_support/multibyte/handlers/utf8_handler.rb +11 -11
- data/lib/active_support/ordered_hash.rb +43 -0
- data/lib/active_support/ordered_options.rb +0 -38
- data/lib/active_support/test_case.rb +10 -2
- data/lib/active_support/testing/default.rb +3 -6
- data/lib/active_support/testing/setup_and_teardown.rb +93 -0
- data/lib/active_support/time_with_zone.rb +283 -0
- data/lib/active_support/values/time_zone.rb +336 -123
- data/lib/active_support/vendor.rb +12 -0
- data/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb +849 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone_info.rb +226 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Algiers.rb +55 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Cairo.rb +219 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Casablanca.rb +38 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Harare.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Monrovia.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Nairobi.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/San_Juan.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Bogota.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Caracas.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chicago.rb +283 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chihuahua.rb +136 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Denver.rb +204 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Godthab.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Guatemala.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Halifax.rb +274 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Juneau.rb +194 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/La_Paz.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Lima.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Los_Angeles.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mazatlan.rb +139 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mexico_City.rb +144 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Monterrey.rb +131 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/New_York.rb +282 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Phoenix.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Regina.rb +74 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Santiago.rb +205 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/St_Johns.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Tijuana.rb +196 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Almaty.rb +67 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baghdad.rb +73 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baku.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Bangkok.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Chongqing.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Dhaka.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jakarta.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kabul.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Karachi.rb +28 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Katmandu.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kolkata.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuwait.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Magadan.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Muscat.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Rangoon.rb +24 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Riyadh.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Seoul.rb +34 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Shanghai.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Singapore.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Taipei.rb +59 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tashkent.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tehran.rb +121 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tokyo.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Urumqi.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yerevan.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Azores.rb +270 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Adelaide.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Brisbane.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Darwin.rb +29 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Hobart.rb +193 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Melbourne.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Perth.rb +37 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Sydney.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc/UTC.rb +16 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Athens.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Belgrade.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Berlin.rb +188 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bratislava.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Brussels.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bucharest.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Budapest.rb +197 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Dublin.rb +276 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Helsinki.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Istanbul.rb +218 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Kiev.rb +168 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Lisbon.rb +268 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/London.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Madrid.rb +211 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Minsk.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Moscow.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Paris.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Prague.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Riga.rb +176 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Rome.rb +215 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Skopje.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sofia.rb +173 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Stockholm.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Tallinn.rb +172 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vienna.rb +183 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vilnius.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Warsaw.rb +212 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Zagreb.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Auckland.rb +202 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Fiji.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Guam.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Majuro.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Midway.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Noumea.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/info_timezone.rb +52 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone.rb +51 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone_info.rb +44 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +95 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/time_or_datetime.rb +292 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone.rb +508 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_definition.rb +56 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_info.rb +40 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_offset_info.rb +94 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_period.rb +198 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_transition_info.rb +138 -0
- data/lib/active_support/version.rb +2 -2
- data/lib/active_support/whiny_nil.rb +30 -10
- metadata +175 -5
- data/lib/active_support/core_ext/rexml.rb +0 -38
- data/lib/active_support/testing.rb +0 -1
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Cache
|
3
|
+
class CompressedMemCacheStore < MemCacheStore
|
4
|
+
def read(name, options = {})
|
5
|
+
if value = super(name, options.merge(:raw => true))
|
6
|
+
Marshal.load(ActiveSupport::Gzip.decompress(value))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def write(name, value, options = {})
|
11
|
+
super(name, ActiveSupport::Gzip.compress(Marshal.dump(value)), options.merge(:raw => true))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'drb'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Cache
|
5
|
+
class DRbStore < MemoryStore #:nodoc:
|
6
|
+
attr_reader :address
|
7
|
+
|
8
|
+
def initialize(address = 'druby://localhost:9192')
|
9
|
+
super()
|
10
|
+
@address = address
|
11
|
+
@data = DRbObject.new(nil, address)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Cache
|
3
|
+
class FileStore < Store
|
4
|
+
attr_reader :cache_path
|
5
|
+
|
6
|
+
def initialize(cache_path)
|
7
|
+
@cache_path = cache_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def read(name, options = nil)
|
11
|
+
super
|
12
|
+
File.open(real_file_path(name), 'rb') { |f| f.read } rescue nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(name, value, options = nil)
|
16
|
+
super
|
17
|
+
ensure_cache_path(File.dirname(real_file_path(name)))
|
18
|
+
File.open(real_file_path(name), "wb+") { |f| f.write(value) }
|
19
|
+
rescue => e
|
20
|
+
RAILS_DEFAULT_LOGGER.error "Couldn't create cache directory: #{name} (#{e.message})" if RAILS_DEFAULT_LOGGER
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(name, options = nil)
|
24
|
+
super
|
25
|
+
File.delete(real_file_path(name))
|
26
|
+
rescue SystemCallError => e
|
27
|
+
# If there's no cache, then there's nothing to complain about
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_matched(matcher, options = nil)
|
31
|
+
super
|
32
|
+
search_dir(@cache_path) do |f|
|
33
|
+
if f =~ matcher
|
34
|
+
begin
|
35
|
+
File.delete(f)
|
36
|
+
rescue SystemCallError => e
|
37
|
+
# If there's no cache, then there's nothing to complain about
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def exist?(name, options = nil)
|
44
|
+
super
|
45
|
+
File.exist?(real_file_path(name))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def real_file_path(name)
|
50
|
+
'%s/%s.cache' % [@cache_path, name.gsub('?', '.').gsub(':', '.')]
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_cache_path(path)
|
54
|
+
FileUtils.makedirs(path) unless File.exist?(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
def search_dir(dir, &callback)
|
58
|
+
Dir.foreach(dir) do |d|
|
59
|
+
next if d == "." || d == ".."
|
60
|
+
name = File.join(dir, d)
|
61
|
+
if File.directory?(name)
|
62
|
+
search_dir(name, &callback)
|
63
|
+
else
|
64
|
+
callback.call name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'memcache'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Cache
|
5
|
+
class MemCacheStore < Store
|
6
|
+
module Response
|
7
|
+
STORED = "STORED\r\n"
|
8
|
+
NOT_STORED = "NOT_STORED\r\n"
|
9
|
+
EXISTS = "EXISTS\r\n"
|
10
|
+
NOT_FOUND = "NOT_FOUND\r\n"
|
11
|
+
DELETED = "DELETED\r\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :addresses
|
15
|
+
|
16
|
+
def initialize(*addresses)
|
17
|
+
addresses = addresses.flatten
|
18
|
+
options = addresses.extract_options!
|
19
|
+
addresses = ["localhost"] if addresses.empty?
|
20
|
+
@addresses = addresses
|
21
|
+
@data = MemCache.new(addresses, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def read(key, options = nil)
|
25
|
+
super
|
26
|
+
@data.get(key, raw?(options))
|
27
|
+
rescue MemCache::MemCacheError => e
|
28
|
+
logger.error("MemCacheError (#{e}): #{e.message}")
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# Set key = value. Pass :unless_exist => true if you don't
|
33
|
+
# want to update the cache if the key is already set.
|
34
|
+
def write(key, value, options = nil)
|
35
|
+
super
|
36
|
+
method = options && options[:unless_exist] ? :add : :set
|
37
|
+
response = @data.send(method, key, value, expires_in(options), raw?(options))
|
38
|
+
response == Response::STORED
|
39
|
+
rescue MemCache::MemCacheError => e
|
40
|
+
logger.error("MemCacheError (#{e}): #{e.message}")
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(key, options = nil)
|
45
|
+
super
|
46
|
+
response = @data.delete(key, expires_in(options))
|
47
|
+
response == Response::DELETED
|
48
|
+
rescue MemCache::MemCacheError => e
|
49
|
+
logger.error("MemCacheError (#{e}): #{e.message}")
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def exist?(key, options = nil)
|
54
|
+
# Doesn't call super, cause exist? in memcache is in fact a read
|
55
|
+
# But who cares? Reading is very fast anyway
|
56
|
+
!read(key, options).nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def increment(key, amount = 1)
|
60
|
+
log("incrementing", key, amount)
|
61
|
+
|
62
|
+
response = @data.incr(key, amount)
|
63
|
+
response == Response::NOT_FOUND ? nil : response
|
64
|
+
rescue MemCache::MemCacheError
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def decrement(key, amount = 1)
|
69
|
+
log("decrement", key, amount)
|
70
|
+
|
71
|
+
response = data.decr(key, amount)
|
72
|
+
response == Response::NOT_FOUND ? nil : response
|
73
|
+
rescue MemCache::MemCacheError
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_matched(matcher, options = nil)
|
78
|
+
super
|
79
|
+
raise "Not supported by Memcache"
|
80
|
+
end
|
81
|
+
|
82
|
+
def clear
|
83
|
+
@data.flush_all
|
84
|
+
end
|
85
|
+
|
86
|
+
def stats
|
87
|
+
@data.stats
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def expires_in(options)
|
92
|
+
(options && options[:expires_in]) || 0
|
93
|
+
end
|
94
|
+
|
95
|
+
def raw?(options)
|
96
|
+
options && options[:raw]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Cache
|
3
|
+
class MemoryStore < Store
|
4
|
+
def initialize
|
5
|
+
@data = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def read(name, options = nil)
|
9
|
+
super
|
10
|
+
@data[name]
|
11
|
+
end
|
12
|
+
|
13
|
+
def write(name, value, options = nil)
|
14
|
+
super
|
15
|
+
@data[name] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(name, options = nil)
|
19
|
+
super
|
20
|
+
@data.delete(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_matched(matcher, options = nil)
|
24
|
+
super
|
25
|
+
@data.delete_if { |k,v| k =~ matcher }
|
26
|
+
end
|
27
|
+
|
28
|
+
def exist?(name,options = nil)
|
29
|
+
super
|
30
|
+
@data.has_key?(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear
|
34
|
+
@data.clear
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
|
3
|
+
# before or after an alteration of the object state.
|
4
|
+
#
|
5
|
+
# Mixing in this module allows you to define callbacks in your class.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# class Storage
|
9
|
+
# include ActiveSupport::Callbacks
|
10
|
+
#
|
11
|
+
# define_callbacks :before_save, :after_save
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class ConfigStorage < Storage
|
15
|
+
# before_save :saving_message
|
16
|
+
# def saving_message
|
17
|
+
# puts "saving..."
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# after_save do |object|
|
21
|
+
# puts "saved"
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def save
|
25
|
+
# run_callbacks(:before_save)
|
26
|
+
# puts "- save"
|
27
|
+
# run_callbacks(:after_save)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# config = ConfigStorage.new
|
32
|
+
# config.save
|
33
|
+
#
|
34
|
+
# Output:
|
35
|
+
# saving...
|
36
|
+
# - save
|
37
|
+
# saved
|
38
|
+
#
|
39
|
+
# Callbacks from parent classes are inherited.
|
40
|
+
#
|
41
|
+
# Example:
|
42
|
+
# class Storage
|
43
|
+
# include ActiveSupport::Callbacks
|
44
|
+
#
|
45
|
+
# define_callbacks :before_save, :after_save
|
46
|
+
#
|
47
|
+
# before_save :prepare
|
48
|
+
# def prepare
|
49
|
+
# puts "preparing save"
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# class ConfigStorage < Storage
|
54
|
+
# before_save :saving_message
|
55
|
+
# def saving_message
|
56
|
+
# puts "saving..."
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# after_save do |object|
|
60
|
+
# puts "saved"
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# def save
|
64
|
+
# run_callbacks(:before_save)
|
65
|
+
# puts "- save"
|
66
|
+
# run_callbacks(:after_save)
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# config = ConfigStorage.new
|
71
|
+
# config.save
|
72
|
+
#
|
73
|
+
# Output:
|
74
|
+
# preparing save
|
75
|
+
# saving...
|
76
|
+
# - save
|
77
|
+
# saved
|
78
|
+
module Callbacks
|
79
|
+
class CallbackChain < Array
|
80
|
+
def self.build(kind, *methods, &block)
|
81
|
+
methods, options = extract_options(*methods, &block)
|
82
|
+
methods.map! { |method| Callback.new(kind, method, options) }
|
83
|
+
new(methods)
|
84
|
+
end
|
85
|
+
|
86
|
+
def run(object, options = {}, &terminator)
|
87
|
+
enumerator = options[:enumerator] || :each
|
88
|
+
|
89
|
+
unless block_given?
|
90
|
+
send(enumerator) { |callback| callback.call(object) }
|
91
|
+
else
|
92
|
+
send(enumerator) do |callback|
|
93
|
+
result = callback.call(object)
|
94
|
+
break result if terminator.call(result, object)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def |(chain)
|
100
|
+
if chain.is_a?(CallbackChain)
|
101
|
+
chain.each { |callback| self | callback }
|
102
|
+
else
|
103
|
+
if (found_callback = find(chain)) && (index = index(chain))
|
104
|
+
self[index] = chain
|
105
|
+
else
|
106
|
+
self << chain
|
107
|
+
end
|
108
|
+
end
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def find(callback, &block)
|
113
|
+
select { |c| c == callback && (!block_given? || yield(c)) }.first
|
114
|
+
end
|
115
|
+
|
116
|
+
def delete(callback)
|
117
|
+
super(callback.is_a?(Callback) ? callback : find(callback))
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
def self.extract_options(*methods, &block)
|
122
|
+
methods.flatten!
|
123
|
+
options = methods.extract_options!
|
124
|
+
methods << block if block_given?
|
125
|
+
return methods, options
|
126
|
+
end
|
127
|
+
|
128
|
+
def extract_options(*methods, &block)
|
129
|
+
self.class.extract_options(*methods, &block)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class Callback
|
134
|
+
attr_reader :kind, :method, :identifier, :options
|
135
|
+
|
136
|
+
def initialize(kind, method, options = {})
|
137
|
+
@kind = kind
|
138
|
+
@method = method
|
139
|
+
@identifier = options[:identifier]
|
140
|
+
@options = options
|
141
|
+
end
|
142
|
+
|
143
|
+
def ==(other)
|
144
|
+
case other
|
145
|
+
when Callback
|
146
|
+
(self.identifier && self.identifier == other.identifier) || self.method == other.method
|
147
|
+
else
|
148
|
+
(self.identifier && self.identifier == other) || self.method == other
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def eql?(other)
|
153
|
+
self == other
|
154
|
+
end
|
155
|
+
|
156
|
+
def dup
|
157
|
+
self.class.new(@kind, @method, @options.dup)
|
158
|
+
end
|
159
|
+
|
160
|
+
def call(*args, &block)
|
161
|
+
evaluate_method(method, *args, &block) if should_run_callback?(*args)
|
162
|
+
rescue LocalJumpError
|
163
|
+
raise ArgumentError,
|
164
|
+
"Cannot yield from a Proc type filter. The Proc must take two " +
|
165
|
+
"arguments and execute #call on the second argument."
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
def evaluate_method(method, *args, &block)
|
170
|
+
case method
|
171
|
+
when Symbol
|
172
|
+
object = args.shift
|
173
|
+
object.send(method, *args, &block)
|
174
|
+
when String
|
175
|
+
eval(method, args.first.instance_eval { binding })
|
176
|
+
when Proc, Method
|
177
|
+
method.call(*args, &block)
|
178
|
+
else
|
179
|
+
if method.respond_to?(kind)
|
180
|
+
method.send(kind, *args, &block)
|
181
|
+
else
|
182
|
+
raise ArgumentError,
|
183
|
+
"Callbacks must be a symbol denoting the method to call, a string to be evaluated, " +
|
184
|
+
"a block to be invoked, or an object responding to the callback method."
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def should_run_callback?(*args)
|
190
|
+
if options[:if]
|
191
|
+
evaluate_method(options[:if], *args)
|
192
|
+
elsif options[:unless]
|
193
|
+
!evaluate_method(options[:unless], *args)
|
194
|
+
else
|
195
|
+
true
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def self.included(base)
|
201
|
+
base.extend ClassMethods
|
202
|
+
end
|
203
|
+
|
204
|
+
module ClassMethods
|
205
|
+
def define_callbacks(*callbacks)
|
206
|
+
callbacks.each do |callback|
|
207
|
+
class_eval <<-"end_eval"
|
208
|
+
def self.#{callback}(*methods, &block)
|
209
|
+
callbacks = CallbackChain.build(:#{callback}, *methods, &block)
|
210
|
+
(@#{callback}_callbacks ||= CallbackChain.new).concat callbacks
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.#{callback}_callback_chain
|
214
|
+
@#{callback}_callbacks ||= CallbackChain.new
|
215
|
+
|
216
|
+
if superclass.respond_to?(:#{callback}_callback_chain)
|
217
|
+
CallbackChain.new(superclass.#{callback}_callback_chain + @#{callback}_callbacks)
|
218
|
+
else
|
219
|
+
@#{callback}_callbacks
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end_eval
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Runs all the callbacks defined for the given options.
|
228
|
+
#
|
229
|
+
# If a block is given it will be called after each callback receiving as arguments:
|
230
|
+
#
|
231
|
+
# * the result from the callback
|
232
|
+
# * the object which has the callback
|
233
|
+
#
|
234
|
+
# If the result from the block evaluates to false, the callback chain is stopped.
|
235
|
+
#
|
236
|
+
# Example:
|
237
|
+
# class Storage
|
238
|
+
# include ActiveSupport::Callbacks
|
239
|
+
#
|
240
|
+
# define_callbacks :before_save, :after_save
|
241
|
+
# end
|
242
|
+
#
|
243
|
+
# class ConfigStorage < Storage
|
244
|
+
# before_save :pass
|
245
|
+
# before_save :pass
|
246
|
+
# before_save :stop
|
247
|
+
# before_save :pass
|
248
|
+
#
|
249
|
+
# def pass
|
250
|
+
# puts "pass"
|
251
|
+
# end
|
252
|
+
#
|
253
|
+
# def stop
|
254
|
+
# puts "stop"
|
255
|
+
# return false
|
256
|
+
# end
|
257
|
+
#
|
258
|
+
# def save
|
259
|
+
# result = run_callbacks(:before_save) { |result, object| result == false }
|
260
|
+
# puts "- save" if result
|
261
|
+
# end
|
262
|
+
# end
|
263
|
+
#
|
264
|
+
# config = ConfigStorage.new
|
265
|
+
# config.save
|
266
|
+
#
|
267
|
+
# Output:
|
268
|
+
# pass
|
269
|
+
# pass
|
270
|
+
# stop
|
271
|
+
def run_callbacks(kind, options = {}, &block)
|
272
|
+
self.class.send("#{kind}_callback_chain").run(self, options, &block)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|