activesupport 3.0.0.beta3 → 3.0.0.beta4

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.

Files changed (63) hide show
  1. data/CHANGELOG +57 -0
  2. data/lib/active_support/builder.rb +6 -0
  3. data/lib/active_support/cache.rb +428 -70
  4. data/lib/active_support/cache/compressed_mem_cache_store.rb +6 -15
  5. data/lib/active_support/cache/file_store.rb +139 -41
  6. data/lib/active_support/cache/mem_cache_store.rb +115 -76
  7. data/lib/active_support/cache/memory_store.rb +127 -27
  8. data/lib/active_support/cache/strategy/local_cache.rb +109 -57
  9. data/lib/active_support/cache/synchronized_memory_store.rb +2 -38
  10. data/lib/active_support/callbacks.rb +27 -27
  11. data/lib/active_support/configurable.rb +19 -18
  12. data/lib/active_support/core_ext/array/conversions.rb +30 -26
  13. data/lib/active_support/core_ext/array/random_access.rb +19 -5
  14. data/lib/active_support/core_ext/benchmark.rb +0 -12
  15. data/lib/active_support/core_ext/class/attribute.rb +1 -4
  16. data/lib/active_support/core_ext/class/inheritable_attributes.rb +3 -0
  17. data/lib/active_support/core_ext/date/calculations.rb +27 -8
  18. data/lib/active_support/core_ext/date/conversions.rb +1 -0
  19. data/lib/active_support/core_ext/date_time/conversions.rb +9 -3
  20. data/lib/active_support/core_ext/file.rb +1 -0
  21. data/lib/active_support/core_ext/hash/conversions.rb +14 -137
  22. data/lib/active_support/core_ext/kernel/debugger.rb +1 -1
  23. data/lib/active_support/core_ext/kernel/reporting.rb +2 -1
  24. data/lib/active_support/core_ext/load_error.rb +1 -0
  25. data/lib/active_support/core_ext/logger.rb +1 -1
  26. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  27. data/lib/active_support/core_ext/object/to_param.rb +2 -2
  28. data/lib/active_support/core_ext/object/with_options.rb +2 -0
  29. data/lib/active_support/core_ext/string.rb +1 -0
  30. data/lib/active_support/core_ext/string/conversions.rb +35 -1
  31. data/lib/active_support/core_ext/string/encoding.rb +11 -0
  32. data/lib/active_support/core_ext/string/filters.rb +29 -0
  33. data/lib/active_support/core_ext/string/inflections.rb +0 -11
  34. data/lib/active_support/core_ext/string/interpolation.rb +1 -0
  35. data/lib/active_support/core_ext/string/multibyte.rb +16 -19
  36. data/lib/active_support/core_ext/time/calculations.rb +7 -6
  37. data/lib/active_support/core_ext/uri.rb +8 -3
  38. data/lib/active_support/dependencies.rb +33 -1
  39. data/lib/active_support/duration.rb +1 -0
  40. data/lib/active_support/hash_with_indifferent_access.rb +5 -1
  41. data/lib/active_support/i18n.rb +7 -2
  42. data/lib/active_support/inflector/transliterate.rb +58 -38
  43. data/lib/active_support/json/encoding.rb +28 -5
  44. data/lib/active_support/lazy_load_hooks.rb +14 -4
  45. data/lib/active_support/locale/en.yml +4 -1
  46. data/lib/active_support/message_verifier.rb +4 -4
  47. data/lib/active_support/multibyte.rb +1 -19
  48. data/lib/active_support/multibyte/chars.rb +143 -427
  49. data/lib/active_support/multibyte/unicode.rb +393 -0
  50. data/lib/active_support/notifications/fanout.rb +15 -5
  51. data/lib/active_support/notifications/instrumenter.rb +10 -4
  52. data/lib/active_support/railtie.rb +36 -0
  53. data/lib/active_support/rescuable.rb +1 -0
  54. data/lib/active_support/ruby/shim.rb +1 -0
  55. data/lib/active_support/testing/declarative.rb +1 -1
  56. data/lib/active_support/testing/isolation.rb +2 -1
  57. data/lib/active_support/testing/setup_and_teardown.rb +3 -0
  58. data/lib/active_support/values/time_zone.rb +20 -30
  59. data/lib/active_support/values/unicode_tables.dat +0 -0
  60. data/lib/active_support/version.rb +1 -1
  61. data/lib/active_support/xml_mini.rb +126 -1
  62. metadata +8 -61
  63. data/lib/active_support/multibyte/unicode_database.rb +0 -71
@@ -33,6 +33,7 @@ module I18n
33
33
  config.i18n = ActiveSupport::OrderedOptions.new
34
34
  config.i18n.railties_load_path = []
35
35
  config.i18n.load_path = []
36
+ config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
36
37
 
37
38
  initializer "i18n.initialize" do
38
39
  ActiveSupport.on_load(:i18n) do
@@ -47,6 +48,8 @@ module I18n
47
48
  # Set the i18n configuration from config.i18n but special-case for
48
49
  # the load_path which should be appended to what's already set instead of overwritten.
49
50
  config.after_initialize do |app|
51
+ fallbacks = app.config.i18n.delete(:fallbacks)
52
+
50
53
  app.config.i18n.each do |setting, value|
51
54
  case setting
52
55
  when :railties_load_path
@@ -58,7 +61,40 @@ module I18n
58
61
  end
59
62
  end
60
63
 
64
+ init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
61
65
  I18n.reload!
62
66
  end
67
+
68
+ class << self
69
+ protected
70
+
71
+ def init_fallbacks(fallbacks)
72
+ include_fallbacks_module
73
+ args = case fallbacks
74
+ when ActiveSupport::OrderedOptions
75
+ [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
76
+ when Hash, Array
77
+ Array.wrap(fallbacks)
78
+ else # TrueClass
79
+ []
80
+ end
81
+ I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
82
+ end
83
+
84
+ def include_fallbacks_module
85
+ I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
86
+ end
87
+
88
+ def validate_fallbacks(fallbacks)
89
+ case fallbacks
90
+ when ActiveSupport::OrderedOptions
91
+ !fallbacks.empty?
92
+ when TrueClass, Array, Hash
93
+ true
94
+ else
95
+ raise "Unexpected fallback type #{fallbacks.inspect}"
96
+ end
97
+ end
98
+ end
63
99
  end
64
100
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/concern'
1
2
  require 'active_support/core_ext/class/attribute'
2
3
  require 'active_support/core_ext/proc'
3
4
  require 'active_support/core_ext/string/inflections'
@@ -15,6 +15,7 @@ require 'active_support/core_ext/enumerable'
15
15
  require 'active_support/core_ext/process/daemon'
16
16
  require 'active_support/core_ext/string/conversions'
17
17
  require 'active_support/core_ext/string/interpolation'
18
+ require 'active_support/core_ext/string/encoding'
18
19
  require 'active_support/core_ext/rexml'
19
20
  require 'active_support/core_ext/time/conversions'
20
21
  require 'active_support/core_ext/file/path'
@@ -7,7 +7,7 @@ module ActiveSupport
7
7
 
8
8
  unless method_defined?(:describe)
9
9
  def self.describe(text)
10
- class_eval <<-RUBY_EVAL
10
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
11
11
  def self.name
12
12
  "#{text}"
13
13
  end
@@ -1,3 +1,4 @@
1
+ require 'rbconfig'
1
2
  module ActiveSupport
2
3
  module Testing
3
4
  class RemoteError < StandardError
@@ -33,7 +34,7 @@ module ActiveSupport
33
34
 
34
35
  module Isolation
35
36
  def self.forking_env?
36
- !ENV["NO_FORK"] && RUBY_PLATFORM !~ /mswin|mingw|java/
37
+ !ENV["NO_FORK"] && ((Config::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
37
38
  end
38
39
 
39
40
  def self.included(base)
@@ -1,3 +1,6 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/callbacks'
3
+
1
4
  module ActiveSupport
2
5
  module Testing
3
6
  module SetupAndTeardown
@@ -1,4 +1,11 @@
1
1
  require 'active_support/core_ext/object/blank'
2
+ require 'active_support/core_ext/object/try'
3
+ begin
4
+ require 'tzinfo'
5
+ rescue LoadError => e
6
+ $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
7
+ raise e
8
+ end
2
9
 
3
10
  # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
4
11
  #
@@ -189,6 +196,7 @@ module ActiveSupport
189
196
 
190
197
  include Comparable
191
198
  attr_reader :name
199
+ attr_reader :tzinfo
192
200
 
193
201
  # Create a new TimeZone object with the given name and offset. The
194
202
  # offset is the number of seconds that this time zone is offset from UTC
@@ -197,7 +205,7 @@ module ActiveSupport
197
205
  def initialize(name, utc_offset = nil, tzinfo = nil)
198
206
  @name = name
199
207
  @utc_offset = utc_offset
200
- @tzinfo = tzinfo
208
+ @tzinfo = tzinfo || TimeZone.find_tzinfo(name)
201
209
  @current_period = nil
202
210
  end
203
211
 
@@ -205,8 +213,8 @@ module ActiveSupport
205
213
  if @utc_offset
206
214
  @utc_offset
207
215
  else
208
- @current_period ||= tzinfo.current_period
209
- @current_period.utc_offset
216
+ @current_period ||= tzinfo.try(:current_period)
217
+ @current_period.try(:utc_offset)
210
218
  end
211
219
  end
212
220
 
@@ -309,32 +317,10 @@ module ActiveSupport
309
317
  tzinfo.period_for_local(time, dst)
310
318
  end
311
319
 
312
- def tzinfo
313
- @tzinfo ||= TimeZone.find_tzinfo(name)
314
- end
315
-
316
320
  # TODO: Preload instead of lazy load for thread safety
317
321
  def self.find_tzinfo(name)
318
- require 'tzinfo' unless defined?(::TZInfo)
319
- ::TZInfo::Timezone.get(MAPPING[name] || name)
320
- rescue TZInfo::InvalidTimezoneIdentifier
321
- nil
322
- end
323
-
324
- unless const_defined?(:ZONES)
325
- ZONES = []
326
- ZONES_MAP = {}
327
- MAPPING.each_key do |place|
328
- place.freeze
329
- zone = new(place)
330
- ZONES << zone
331
- ZONES_MAP[place] = zone
332
- end
333
- ZONES.sort!
334
- ZONES.freeze
335
-
336
- US_ZONES = ZONES.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
337
- US_ZONES.freeze
322
+ require 'active_support/tzinfo' unless defined?(::TZInfo)
323
+ ::TZInfo::TimezoneProxy.new(MAPPING[name] || name)
338
324
  end
339
325
 
340
326
  class << self
@@ -351,7 +337,11 @@ module ActiveSupport
351
337
  # TimeZone objects per time zone, in many cases, to make it easier
352
338
  # for users to find their own time zone.
353
339
  def all
354
- ZONES
340
+ @zones ||= zones_map.values.sort
341
+ end
342
+
343
+ def zones_map
344
+ @zones_map ||= Hash[MAPPING.map { |place, _| [place, create(place)] }]
355
345
  end
356
346
 
357
347
  # Locate a specific time zone object. If the argument is a string, it
@@ -362,7 +352,7 @@ module ActiveSupport
362
352
  def [](arg)
363
353
  case arg
364
354
  when String
365
- ZONES_MAP[arg] ||= lookup(arg)
355
+ zones_map[arg] ||= lookup(arg)
366
356
  when Numeric, ActiveSupport::Duration
367
357
  arg *= 3600 if arg.abs <= 13
368
358
  all.find { |z| z.utc_offset == arg.to_i }
@@ -374,7 +364,7 @@ module ActiveSupport
374
364
  # A convenience method for returning a collection of TimeZone objects
375
365
  # for time zones in the USA.
376
366
  def us_zones
377
- US_ZONES
367
+ @us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
378
368
  end
379
369
 
380
370
  private
@@ -3,7 +3,7 @@ module ActiveSupport
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  TINY = 0
6
- BUILD = "beta3"
6
+ BUILD = "beta4"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
9
  end
@@ -9,6 +9,71 @@ module ActiveSupport
9
9
  module XmlMini
10
10
  extend self
11
11
 
12
+ # This module exists to decorate files deserialized using Hash.from_xml with
13
+ # the <tt>original_filename</tt> and <tt>content_type</tt> methods.
14
+ module FileLike #:nodoc:
15
+ attr_writer :original_filename, :content_type
16
+
17
+ def original_filename
18
+ @original_filename || 'untitled'
19
+ end
20
+
21
+ def content_type
22
+ @content_type || 'application/octet-stream'
23
+ end
24
+ end
25
+
26
+ DEFAULT_ENCODINGS = {
27
+ "binary" => "base64"
28
+ } unless defined?(TYPE_NAMES)
29
+
30
+ TYPE_NAMES = {
31
+ "Symbol" => "symbol",
32
+ "Fixnum" => "integer",
33
+ "Bignum" => "integer",
34
+ "BigDecimal" => "decimal",
35
+ "Float" => "float",
36
+ "TrueClass" => "boolean",
37
+ "FalseClass" => "boolean",
38
+ "Date" => "date",
39
+ "DateTime" => "datetime",
40
+ "Time" => "datetime",
41
+ "Array" => "array",
42
+ "Hash" => "hash"
43
+ } unless defined?(TYPE_NAMES)
44
+
45
+ FORMATTING = {
46
+ "symbol" => Proc.new { |symbol| symbol.to_s },
47
+ "date" => Proc.new { |date| date.to_s(:db) },
48
+ "datetime" => Proc.new { |time| time.xmlschema },
49
+ "binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) },
50
+ "yaml" => Proc.new { |yaml| yaml.to_yaml }
51
+ } unless defined?(FORMATTING)
52
+
53
+ # TODO: use Time.xmlschema instead of Time.parse;
54
+ # use regexp instead of Date.parse
55
+ unless defined?(PARSING)
56
+ PARSING = {
57
+ "symbol" => Proc.new { |symbol| symbol.to_sym },
58
+ "date" => Proc.new { |date| ::Date.parse(date) },
59
+ "datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc },
60
+ "integer" => Proc.new { |integer| integer.to_i },
61
+ "float" => Proc.new { |float| float.to_f },
62
+ "decimal" => Proc.new { |number| BigDecimal(number) },
63
+ "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
64
+ "string" => Proc.new { |string| string.to_s },
65
+ "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
66
+ "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
67
+ "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
68
+ "file" => Proc.new { |file, entity| _parse_file(file, entity) }
69
+ }
70
+
71
+ PARSING.update(
72
+ "double" => PARSING["float"],
73
+ "dateTime" => PARSING["datetime"]
74
+ )
75
+ end
76
+
12
77
  attr_reader :backend
13
78
  delegate :parse, :to => :backend
14
79
 
@@ -16,7 +81,7 @@ module ActiveSupport
16
81
  if name.is_a?(Module)
17
82
  @backend = name
18
83
  else
19
- require "active_support/xml_mini/#{name.to_s.downcase}.rb"
84
+ require "active_support/xml_mini/#{name.to_s.downcase}"
20
85
  @backend = ActiveSupport.const_get("XmlMini_#{name}")
21
86
  end
22
87
  end
@@ -27,6 +92,66 @@ module ActiveSupport
27
92
  ensure
28
93
  self.backend = old_backend
29
94
  end
95
+
96
+ def to_tag(key, value, options)
97
+ type_name = options.delete(:type)
98
+ merged_options = options.merge(:root => key, :skip_instruct => true)
99
+
100
+ if value.is_a?(::Method) || value.is_a?(::Proc)
101
+ if value.arity == 1
102
+ value.call(merged_options)
103
+ else
104
+ value.call(merged_options, key.to_s.singularize)
105
+ end
106
+ elsif value.respond_to?(:to_xml)
107
+ value.to_xml(merged_options)
108
+ else
109
+ type_name ||= TYPE_NAMES[value.class.name]
110
+ type_name ||= value.class.name if value && !value.respond_to?(:to_str)
111
+ type_name = type_name.to_s if type_name
112
+
113
+ key = rename_key(key.to_s, options)
114
+
115
+ attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name }
116
+ attributes[:nil] = true if value.nil?
117
+
118
+ encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
119
+ attributes[:encoding] = encoding if encoding
120
+
121
+ formatted_value = FORMATTING[type_name] && !value.nil? ?
122
+ FORMATTING[type_name].call(value) : value
123
+
124
+ options[:builder].tag!(key, formatted_value, attributes)
125
+ end
126
+ end
127
+
128
+ def rename_key(key, options = {})
129
+ camelize = options.has_key?(:camelize) && options[:camelize]
130
+ dasherize = !options.has_key?(:dasherize) || options[:dasherize]
131
+ key = key.camelize if camelize
132
+ key = key.dasherize if dasherize
133
+ key
134
+ end
135
+
136
+ protected
137
+
138
+ # TODO: Add support for other encodings
139
+ def _parse_binary(bin, entity) #:nodoc:
140
+ case entity['encoding']
141
+ when 'base64'
142
+ ActiveSupport::Base64.decode64(bin)
143
+ else
144
+ bin
145
+ end
146
+ end
147
+
148
+ def _parse_file(file, entity)
149
+ f = StringIO.new(ActiveSupport::Base64.decode64(file))
150
+ f.extend(FileLike)
151
+ f.original_filename = entity['name']
152
+ f.content_type = entity['content_type']
153
+ f
154
+ end
30
155
  end
31
156
 
32
157
  XmlMini.backend = 'REXML'
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 3
7
7
  - 0
8
8
  - 0
9
- - beta3
10
- version: 3.0.0.beta3
9
+ - beta4
10
+ version: 3.0.0.beta4
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Heinemeier Hansson
@@ -15,65 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-13 00:00:00 -07:00
18
+ date: 2010-06-08 00:00:00 -04:00
19
19
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: i18n
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 3
31
- - 6
32
- version: 0.3.6
33
- type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: tzinfo
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- - 3
45
- - 16
46
- version: 0.3.16
47
- type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: builder
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- segments:
57
- - 2
58
- - 1
59
- - 2
60
- version: 2.1.2
61
- type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: memcache-client
65
- prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- segments:
71
- - 1
72
- - 7
73
- - 5
74
- version: 1.7.5
75
- type: :runtime
76
- version_requirements: *id004
20
+ dependencies: []
21
+
77
22
  description: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.
78
23
  email: david@loudthinking.com
79
24
  executables: []
@@ -91,6 +36,7 @@ files:
91
36
  - lib/active_support/basic_object.rb
92
37
  - lib/active_support/benchmarkable.rb
93
38
  - lib/active_support/buffered_logger.rb
39
+ - lib/active_support/builder.rb
94
40
  - lib/active_support/cache/compressed_mem_cache_store.rb
95
41
  - lib/active_support/cache/file_store.rb
96
42
  - lib/active_support/cache/mem_cache_store.rb
@@ -199,6 +145,7 @@ files:
199
145
  - lib/active_support/core_ext/string/access.rb
200
146
  - lib/active_support/core_ext/string/behavior.rb
201
147
  - lib/active_support/core_ext/string/conversions.rb
148
+ - lib/active_support/core_ext/string/encoding.rb
202
149
  - lib/active_support/core_ext/string/exclude.rb
203
150
  - lib/active_support/core_ext/string/filters.rb
204
151
  - lib/active_support/core_ext/string/inflections.rb
@@ -246,7 +193,7 @@ files:
246
193
  - lib/active_support/message_verifier.rb
247
194
  - lib/active_support/multibyte/chars.rb
248
195
  - lib/active_support/multibyte/exceptions.rb
249
- - lib/active_support/multibyte/unicode_database.rb
196
+ - lib/active_support/multibyte/unicode.rb
250
197
  - lib/active_support/multibyte/utils.rb
251
198
  - lib/active_support/multibyte.rb
252
199
  - lib/active_support/notifications/fanout.rb