activesupport 4.1.0.beta2 → 4.1.0.rc1

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +166 -8
  3. data/MIT-LICENSE +1 -1
  4. data/lib/active_support.rb +1 -1
  5. data/lib/active_support/cache.rb +2 -2
  6. data/lib/active_support/cache/mem_cache_store.rb +6 -8
  7. data/lib/active_support/cache/strategy/local_cache.rb +8 -2
  8. data/lib/active_support/callbacks.rb +1 -1
  9. data/lib/active_support/configurable.rb +1 -1
  10. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -15
  11. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +14 -0
  12. data/lib/active_support/core_ext/class/delegating_attributes.rb +9 -8
  13. data/lib/active_support/core_ext/date/conversions.rb +5 -2
  14. data/lib/active_support/core_ext/date_time/calculations.rb +5 -1
  15. data/lib/active_support/core_ext/enumerable.rb +1 -1
  16. data/lib/active_support/core_ext/hash.rb +1 -0
  17. data/lib/active_support/core_ext/hash/compact.rb +20 -0
  18. data/lib/active_support/core_ext/hash/conversions.rb +1 -1
  19. data/lib/active_support/core_ext/hash/except.rb +1 -1
  20. data/lib/active_support/core_ext/hash/keys.rb +6 -6
  21. data/lib/active_support/core_ext/module/attr_internal.rb +2 -1
  22. data/lib/active_support/core_ext/module/concerning.rb +1 -1
  23. data/lib/active_support/core_ext/module/delegation.rb +22 -20
  24. data/lib/active_support/core_ext/object/blank.rb +43 -17
  25. data/lib/active_support/core_ext/object/inclusion.rb +12 -0
  26. data/lib/active_support/core_ext/object/json.rb +4 -4
  27. data/lib/active_support/core_ext/object/to_param.rb +7 -3
  28. data/lib/active_support/core_ext/object/to_query.rb +6 -1
  29. data/lib/active_support/core_ext/range/each.rb +1 -2
  30. data/lib/active_support/core_ext/string/access.rb +1 -1
  31. data/lib/active_support/core_ext/string/output_safety.rb +12 -12
  32. data/lib/active_support/core_ext/thread.rb +1 -1
  33. data/lib/active_support/core_ext/time/calculations.rb +6 -4
  34. data/lib/active_support/dependencies.rb +10 -1
  35. data/lib/active_support/hash_with_indifferent_access.rb +7 -3
  36. data/lib/active_support/i18n_railtie.rb +1 -1
  37. data/lib/active_support/inflections.rb +6 -0
  38. data/lib/active_support/inflector/methods.rb +1 -1
  39. data/lib/active_support/json/encoding.rb +7 -1
  40. data/lib/active_support/key_generator.rb +7 -9
  41. data/lib/active_support/message_encryptor.rb +1 -1
  42. data/lib/active_support/multibyte/unicode.rb +36 -36
  43. data/lib/active_support/number_helper/number_to_rounded_converter.rb +37 -7
  44. data/lib/active_support/ordered_hash.rb +4 -0
  45. data/lib/active_support/testing/isolation.rb +2 -0
  46. data/lib/active_support/testing/time_helpers.rb +84 -12
  47. data/lib/active_support/time_with_zone.rb +8 -7
  48. data/lib/active_support/values/time_zone.rb +9 -21
  49. data/lib/active_support/values/unicode_tables.dat +0 -0
  50. data/lib/active_support/version.rb +1 -1
  51. data/lib/active_support/xml_mini.rb +4 -2
  52. metadata +3 -1
@@ -45,7 +45,7 @@ module ActiveSupport
45
45
 
46
46
  def initialize(utc_time, time_zone, local_time = nil, period = nil)
47
47
  @utc, @time_zone, @time = utc_time, time_zone, local_time
48
- @period = @utc ? period : get_period_and_ensure_valid_local_time
48
+ @period = @utc ? period : get_period_and_ensure_valid_local_time(period)
49
49
  end
50
50
 
51
51
  # Returns a Time or DateTime instance that represents the time in +time_zone+.
@@ -132,8 +132,8 @@ module ActiveSupport
132
132
  end
133
133
 
134
134
  def xmlschema(fraction_digits = 0)
135
- fraction = if fraction_digits > 0
136
- (".%06i" % time.usec)[0, fraction_digits + 1]
135
+ fraction = if fraction_digits.to_i > 0
136
+ (".%06i" % time.usec)[0, fraction_digits.to_i + 1]
137
137
  end
138
138
 
139
139
  "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}"
@@ -154,7 +154,7 @@ module ActiveSupport
154
154
  # # => "2005/02/01 05:15:10 -1000"
155
155
  def as_json(options = nil)
156
156
  if ActiveSupport::JSON::Encoding.use_standard_json_time_format
157
- xmlschema(3)
157
+ xmlschema(ActiveSupport::JSON::Encoding.time_precision)
158
158
  else
159
159
  %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
160
160
  end
@@ -367,12 +367,12 @@ module ActiveSupport
367
367
  end
368
368
 
369
369
  private
370
- def get_period_and_ensure_valid_local_time
370
+ def get_period_and_ensure_valid_local_time(period)
371
371
  # we don't want a Time.local instance enforcing its own DST rules as well,
372
372
  # so transfer time values to a utc constructor if necessary
373
373
  @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
374
374
  begin
375
- @time_zone.period_for_local(@time)
375
+ period || @time_zone.period_for_local(@time)
376
376
  rescue ::TZInfo::PeriodNotFound
377
377
  # time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again
378
378
  @time += 1.hour
@@ -390,7 +390,8 @@ module ActiveSupport
390
390
 
391
391
  def wrap_with_time_zone(time)
392
392
  if time.acts_like?(:time)
393
- self.class.new(nil, time_zone, time)
393
+ periods = time_zone.periods_for_local(time)
394
+ self.class.new(nil, time_zone, time, periods.include?(period) ? period : nil)
394
395
  elsif time.is_a?(Range)
395
396
  wrap_with_time_zone(time.begin)..wrap_with_time_zone(time.end)
396
397
  else
@@ -1,3 +1,4 @@
1
+ require 'tzinfo'
1
2
  require 'thread_safe'
2
3
  require 'active_support/core_ext/object/blank'
3
4
  require 'active_support/core_ext/object/try'
@@ -208,8 +209,6 @@ module ActiveSupport
208
209
  # (GMT). Seconds were chosen as the offset unit because that is the unit
209
210
  # that Ruby uses to represent time zone offsets (see Time#utc_offset).
210
211
  def initialize(name, utc_offset = nil, tzinfo = nil)
211
- self.class.send(:require_tzinfo)
212
-
213
212
  @name = name
214
213
  @utc_offset = utc_offset
215
214
  @tzinfo = tzinfo || TimeZone.find_tzinfo(name)
@@ -235,6 +234,7 @@ module ActiveSupport
235
234
  # Compare this time zone to the parameter. The two are compared first on
236
235
  # their offsets, and then by name.
237
236
  def <=>(zone)
237
+ return unless zone.respond_to? :utc_offset
238
238
  result = (utc_offset <=> zone.utc_offset)
239
239
  result = (name <=> zone.name) if result == 0
240
240
  result
@@ -352,6 +352,10 @@ module ActiveSupport
352
352
  tzinfo.period_for_local(time, dst)
353
353
  end
354
354
 
355
+ def periods_for_local(time) #:nodoc:
356
+ tzinfo.periods_for_local(time)
357
+ end
358
+
355
359
  def self.find_tzinfo(name)
356
360
  TZInfo::TimezoneProxy.new(MAPPING[name] || name)
357
361
  end
@@ -359,14 +363,14 @@ module ActiveSupport
359
363
  class << self
360
364
  alias_method :create, :new
361
365
 
362
- # Return a TimeZone instance with the given name, or +nil+ if no
366
+ # Returns a TimeZone instance with the given name, or +nil+ if no
363
367
  # such TimeZone instance exists. (This exists to support the use of
364
368
  # this class with the +composed_of+ macro.)
365
369
  def new(name)
366
370
  self[name]
367
371
  end
368
372
 
369
- # Return an array of all TimeZone objects. There are multiple
373
+ # Returns an array of all TimeZone objects. There are multiple
370
374
  # TimeZone objects per time zone, in many cases, to make it easier
371
375
  # for users to find their own time zone.
372
376
  def all
@@ -389,7 +393,7 @@ module ActiveSupport
389
393
  case arg
390
394
  when String
391
395
  begin
392
- lazy_zones_map[arg] ||= create(arg).tap { |tz| tz.utc_offset }
396
+ @lazy_zones_map[arg] ||= create(arg).tap { |tz| tz.utc_offset }
393
397
  rescue TZInfo::InvalidTimezoneIdentifier
394
398
  nil
395
399
  end
@@ -406,22 +410,6 @@ module ActiveSupport
406
410
  def us_zones
407
411
  @us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
408
412
  end
409
-
410
- protected
411
-
412
- def require_tzinfo
413
- require 'tzinfo' unless defined?(::TZInfo)
414
- rescue LoadError
415
- $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
416
- raise
417
- end
418
-
419
- private
420
-
421
- def lazy_zones_map
422
- require_tzinfo
423
- @lazy_zones_map
424
- end
425
413
  end
426
414
 
427
415
  private
@@ -1,7 +1,7 @@
1
1
  module ActiveSupport
2
2
  # Returns the version of the currently loaded ActiveSupport as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new "4.1.0.beta2"
4
+ Gem::Version.new "4.1.0.rc1"
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
@@ -1,7 +1,9 @@
1
1
  require 'time'
2
2
  require 'base64'
3
+ require 'bigdecimal'
3
4
  require 'active_support/core_ext/module/delegation'
4
5
  require 'active_support/core_ext/string/inflections'
6
+ require 'active_support/core_ext/date_time/calculations'
5
7
 
6
8
  module ActiveSupport
7
9
  # = XmlMini
@@ -56,13 +58,13 @@ module ActiveSupport
56
58
  # TODO use regexp instead of Date.parse
57
59
  unless defined?(PARSING)
58
60
  PARSING = {
59
- "symbol" => Proc.new { |symbol| symbol.to_sym },
61
+ "symbol" => Proc.new { |symbol| symbol.to_s.to_sym },
60
62
  "date" => Proc.new { |date| ::Date.parse(date) },
61
63
  "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
62
64
  "integer" => Proc.new { |integer| integer.to_i },
63
65
  "float" => Proc.new { |float| float.to_f },
64
66
  "decimal" => Proc.new { |number| BigDecimal(number) },
65
- "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
67
+ "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
66
68
  "string" => Proc.new { |string| string.to_s },
67
69
  "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
68
70
  "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.beta2
4
+ version: 4.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -129,6 +129,7 @@ files:
129
129
  - lib/active_support/core_ext/benchmark.rb
130
130
  - lib/active_support/core_ext/big_decimal.rb
131
131
  - lib/active_support/core_ext/big_decimal/conversions.rb
132
+ - lib/active_support/core_ext/big_decimal/yaml_conversions.rb
132
133
  - lib/active_support/core_ext/class.rb
133
134
  - lib/active_support/core_ext/class/attribute.rb
134
135
  - lib/active_support/core_ext/class/attribute_accessors.rb
@@ -150,6 +151,7 @@ files:
150
151
  - lib/active_support/core_ext/file.rb
151
152
  - lib/active_support/core_ext/file/atomic.rb
152
153
  - lib/active_support/core_ext/hash.rb
154
+ - lib/active_support/core_ext/hash/compact.rb
153
155
  - lib/active_support/core_ext/hash/conversions.rb
154
156
  - lib/active_support/core_ext/hash/deep_merge.rb
155
157
  - lib/active_support/core_ext/hash/except.rb