activesupport 5.0.1 → 5.0.2.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f7f5a77000a9e0e613dae1720ca87243bdb369f
4
- data.tar.gz: a952482a8d6b4c40c867c6aa5a81a12c2e254f29
3
+ metadata.gz: 84ee84b518cd5d01572e17aa2459eb4b574e9f44
4
+ data.tar.gz: 93cdb19e7e5433f311a74976c252936fd8f9e424
5
5
  SHA512:
6
- metadata.gz: b8041b5c67e2cac257b19e11d93ef0a58f8d38427f4aae8e131c6c2731bb65c7a7c897fb3626d837a662b51040576f6becc5815f88e91f7adb508d507a2f9043
7
- data.tar.gz: 2491790523294a1c59766717e04f1b9c938c9dc5fadb48699513a7f72856c24001149355b58ffdb2faee530308241e0f5501864903594740a2207022492682d4
6
+ metadata.gz: ccdcffd35ec75b325c71108bba8f7d4bb5f2af68f6779387efdb8a0b6054e7cb4719d29646e0277c72f02e3b330798978fdd5cd34dfbf8d2ad951c4f761d0279
7
+ data.tar.gz: ac6fa11430bcb7eb7097a98ee048d18ce8ed1cd595cd199d28ec67ea01747cd9eba993a6c4c450db1138b8a864a359de504d87385388edd248936849d5627f08
@@ -1,3 +1,20 @@
1
+ ## Rails 5.0.2.rc1 (February 24, 2017) ##
2
+
3
+ * In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
4
+ argument for `Marshal#load( source [, proc] )`. This way we don't have to do
5
+ `Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
6
+
7
+ *Jeff Latz*
8
+
9
+ * `ActiveSupport::Gzip.decompress` now checks checksum and length in footer.
10
+
11
+ *Dylan Thacker-Smith*
12
+
13
+ * Cache `ActiveSupport::TimeWithZone#to_datetime` before freezing.
14
+
15
+ *Adam Rice*
16
+
17
+
1
18
  ## Rails 5.0.1 (December 21, 2016) ##
2
19
 
3
20
  * No changes.
@@ -1,20 +1,24 @@
1
1
  class Hash
2
- # Returns a hash with non +nil+ values.
3
- #
4
- # hash = { a: true, b: false, c: nil}
5
- # hash.compact # => { a: true, b: false}
6
- # hash # => { a: true, b: false, c: nil}
7
- # { c: nil }.compact # => {}
8
- def compact
9
- self.select { |_, value| !value.nil? }
2
+ unless Hash.instance_methods(false).include?(:compact)
3
+ # Returns a hash with non +nil+ values.
4
+ #
5
+ # hash = { a: true, b: false, c: nil}
6
+ # hash.compact # => { a: true, b: false}
7
+ # hash # => { a: true, b: false, c: nil}
8
+ # { c: nil }.compact # => {}
9
+ def compact
10
+ self.select { |_, value| !value.nil? }
11
+ end
10
12
  end
11
13
 
12
- # Replaces current hash with non +nil+ values.
13
- #
14
- # hash = { a: true, b: false, c: nil}
15
- # hash.compact! # => { a: true, b: false}
16
- # hash # => { a: true, b: false}
17
- def compact!
18
- self.reject! { |_, value| value.nil? }
14
+ unless Hash.instance_methods(false).include?(:compact!)
15
+ # Replaces current hash with non +nil+ values.
16
+ #
17
+ # hash = { a: true, b: false, c: nil}
18
+ # hash.compact! # => { a: true, b: false}
19
+ # hash # => { a: true, b: false}
20
+ def compact!
21
+ self.reject! { |_, value| value.nil? }
22
+ end
19
23
  end
20
24
  end
@@ -16,7 +16,7 @@ class Hash
16
16
  result[key] = yield(value)
17
17
  end
18
18
  result
19
- end
19
+ end unless method_defined? :transform_values
20
20
 
21
21
  # Destructively converts all values using the +block+ operations.
22
22
  # Same as +transform_values+ but modifies +self+.
@@ -25,5 +25,5 @@ class Hash
25
25
  each do |key, value|
26
26
  self[key] = yield(value)
27
27
  end
28
- end
28
+ end unless method_defined? :transform_values!
29
29
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveSupport
2
2
  module MarshalWithAutoloading # :nodoc:
3
- def load(source)
4
- super(source)
3
+ def load(source, proc = nil)
4
+ super(source, proc)
5
5
  rescue ArgumentError, NameError => exc
6
6
  if exc.message.match(%r|undefined class/module (.+?)(?:::)?\z|)
7
7
  # try loading the class/module
@@ -5,10 +5,12 @@ class Module
5
5
  #
6
6
  # M::N.parent_name # => "M"
7
7
  def parent_name
8
- if defined? @parent_name
8
+ if defined?(@parent_name)
9
9
  @parent_name
10
10
  else
11
- @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
11
+ parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
12
+ @parent_name = parent_name unless frozen?
13
+ parent_name
12
14
  end
13
15
  end
14
16
 
@@ -100,31 +100,30 @@ module ActiveSupport::NumericWithFormat
100
100
  # 1234567.to_s(:human, precision: 1,
101
101
  # separator: ',',
102
102
  # significant: false) # => "1,2 Million"
103
- def to_s(*args)
104
- format, options = args
105
- options ||= {}
106
-
103
+ def to_s(format = nil, options = nil)
107
104
  case format
105
+ when nil
106
+ super()
107
+ when Integer, String
108
+ super(format)
108
109
  when :phone
109
- return ActiveSupport::NumberHelper.number_to_phone(self, options)
110
+ return ActiveSupport::NumberHelper.number_to_phone(self, options || {})
110
111
  when :currency
111
- return ActiveSupport::NumberHelper.number_to_currency(self, options)
112
+ return ActiveSupport::NumberHelper.number_to_currency(self, options || {})
112
113
  when :percentage
113
- return ActiveSupport::NumberHelper.number_to_percentage(self, options)
114
+ return ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
114
115
  when :delimited
115
- return ActiveSupport::NumberHelper.number_to_delimited(self, options)
116
+ return ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
116
117
  when :rounded
117
- return ActiveSupport::NumberHelper.number_to_rounded(self, options)
118
+ return ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
118
119
  when :human
119
- return ActiveSupport::NumberHelper.number_to_human(self, options)
120
+ return ActiveSupport::NumberHelper.number_to_human(self, options || {})
120
121
  when :human_size
121
- return ActiveSupport::NumberHelper.number_to_human_size(self, options)
122
+ return ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
123
+ when Symbol
124
+ super()
122
125
  else
123
- if is_a?(Float) || format.is_a?(Symbol)
124
- super()
125
- else
126
- super
127
- end
126
+ super(format)
128
127
  end
129
128
  end
130
129
 
@@ -135,7 +134,7 @@ module ActiveSupport::NumericWithFormat
135
134
  end
136
135
 
137
136
  # Ruby 2.4+ unifies Fixnum & Bignum into Integer.
138
- if Integer == Fixnum
137
+ if 0.class == Integer
139
138
  Integer.prepend ActiveSupport::NumericWithFormat
140
139
  else
141
140
  Fixnum.prepend ActiveSupport::NumericWithFormat
@@ -1,7 +1,7 @@
1
1
  #--
2
- # Most objects are cloneable, but not all. For example you can't dup +nil+:
2
+ # Most objects are cloneable, but not all. For example you can't dup methods:
3
3
  #
4
- # nil.dup # => TypeError: can't dup NilClass
4
+ # method(:puts).dup # => TypeError: allocator undefined for Method
5
5
  #
6
6
  # Classes may signal their instances are not duplicable removing +dup+/+clone+
7
7
  # or raising exceptions from them. So, to dup an arbitrary object you normally
@@ -19,7 +19,7 @@
19
19
  class Object
20
20
  # Can you safely dup this object?
21
21
  #
22
- # False for +nil+, +false+, +true+, symbol, number, method objects;
22
+ # False for method objects;
23
23
  # true otherwise.
24
24
  def duplicable?
25
25
  true
@@ -27,52 +27,78 @@ class Object
27
27
  end
28
28
 
29
29
  class NilClass
30
- # +nil+ is not duplicable:
31
- #
32
- # nil.duplicable? # => false
33
- # nil.dup # => TypeError: can't dup NilClass
34
- def duplicable?
35
- false
30
+ begin
31
+ nil.dup
32
+ rescue TypeError
33
+
34
+ # +nil+ is not duplicable:
35
+ #
36
+ # nil.duplicable? # => false
37
+ # nil.dup # => TypeError: can't dup NilClass
38
+ def duplicable?
39
+ false
40
+ end
36
41
  end
37
42
  end
38
43
 
39
44
  class FalseClass
40
- # +false+ is not duplicable:
41
- #
42
- # false.duplicable? # => false
43
- # false.dup # => TypeError: can't dup FalseClass
44
- def duplicable?
45
- false
45
+ begin
46
+ false.dup
47
+ rescue TypeError
48
+
49
+ # +false+ is not duplicable:
50
+ #
51
+ # false.duplicable? # => false
52
+ # false.dup # => TypeError: can't dup FalseClass
53
+ def duplicable?
54
+ false
55
+ end
46
56
  end
47
57
  end
48
58
 
49
59
  class TrueClass
50
- # +true+ is not duplicable:
51
- #
52
- # true.duplicable? # => false
53
- # true.dup # => TypeError: can't dup TrueClass
54
- def duplicable?
55
- false
60
+ begin
61
+ true.dup
62
+ rescue TypeError
63
+
64
+ # +true+ is not duplicable:
65
+ #
66
+ # true.duplicable? # => false
67
+ # true.dup # => TypeError: can't dup TrueClass
68
+ def duplicable?
69
+ false
70
+ end
56
71
  end
57
72
  end
58
73
 
59
74
  class Symbol
60
- # Symbols are not duplicable:
61
- #
62
- # :my_symbol.duplicable? # => false
63
- # :my_symbol.dup # => TypeError: can't dup Symbol
64
- def duplicable?
65
- false
75
+ begin
76
+ :symbol.dup # Ruby 2.4.x.
77
+ 'symbol_from_string'.to_sym.dup # Some symbols can't `dup` in Ruby 2.4.0.
78
+ rescue TypeError
79
+
80
+ # Symbols are not duplicable:
81
+ #
82
+ # :my_symbol.duplicable? # => false
83
+ # :my_symbol.dup # => TypeError: can't dup Symbol
84
+ def duplicable?
85
+ false
86
+ end
66
87
  end
67
88
  end
68
89
 
69
90
  class Numeric
70
- # Numbers are not duplicable:
71
- #
72
- # 3.duplicable? # => false
73
- # 3.dup # => TypeError: can't dup Integer
74
- def duplicable?
75
- false
91
+ begin
92
+ 1.dup
93
+ rescue TypeError
94
+
95
+ # Numbers are not duplicable:
96
+ #
97
+ # 3.duplicable? # => false
98
+ # 3.dup # => TypeError: can't dup Integer
99
+ def duplicable?
100
+ false
101
+ end
76
102
  end
77
103
  end
78
104
 
@@ -7,8 +7,8 @@ module ActiveSupport
7
7
  module VERSION
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
- TINY = 1
11
- PRE = nil
10
+ TINY = 2
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -21,7 +21,7 @@ module ActiveSupport
21
21
 
22
22
  # Decompresses a gzipped string.
23
23
  def self.decompress(source)
24
- Zlib::GzipReader.new(StringIO.new(source)).read
24
+ Zlib::GzipReader.wrap(StringIO.new(source), &:read)
25
25
  end
26
26
 
27
27
  # Compresses a string using gzip.
@@ -274,6 +274,15 @@ module ActiveSupport
274
274
  dup.tap { |hash| hash.reject!(*args, &block) }
275
275
  end
276
276
 
277
+ def transform_values(*args, &block)
278
+ return to_enum(:transform_values) unless block_given?
279
+ dup.tap { |hash| hash.transform_values!(*args, &block) }
280
+ end
281
+
282
+ def compact
283
+ dup.tap(&:compact!)
284
+ end
285
+
277
286
  # Convert to a regular hash with string keys.
278
287
  def to_hash
279
288
  _new_hash = Hash.new
@@ -273,7 +273,7 @@ module ActiveSupport
273
273
 
274
274
  # Go down the ancestors to check if it is owned directly. The check
275
275
  # stops when we reach Object or the end of ancestors tree.
276
- constant = constant.ancestors.inject do |const, ancestor|
276
+ constant = constant.ancestors.inject(constant) do |const, ancestor|
277
277
  break const if ancestor == Object
278
278
  break ancestor if ancestor.const_defined?(name, false)
279
279
  const
@@ -84,7 +84,7 @@ module ActiveSupport
84
84
  when String
85
85
  EscapedString.new(value)
86
86
  when Numeric, NilClass, TrueClass, FalseClass
87
- value
87
+ value.as_json
88
88
  when Hash
89
89
  Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
90
90
  when Array
@@ -13,10 +13,10 @@ module ActiveSupport
13
13
  # where you don't want users to be able to determine the value of the payload.
14
14
  #
15
15
  # salt = SecureRandom.random_bytes(64)
16
- # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\x89\xE0\x156\xAC..."
17
- # crypt = ActiveSupport::MessageEncryptor.new(key) # => #<ActiveSupport::MessageEncryptor ...>
18
- # encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..."
19
- # crypt.decrypt_and_verify(encrypted_data) # => "my secret data"
16
+ # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt, 32) # => "\x89\xE0\x156\xAC..."
17
+ # crypt = ActiveSupport::MessageEncryptor.new(key) # => #<ActiveSupport::MessageEncryptor ...>
18
+ # encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..."
19
+ # crypt.decrypt_and_verify(encrypted_data) # => "my secret data"
20
20
  class MessageEncryptor
21
21
  DEFAULT_CIPHER = "aes-256-cbc"
22
22
 
@@ -2,8 +2,8 @@ gem 'minitest'
2
2
 
3
3
  require 'minitest'
4
4
 
5
- if Minitest.respond_to?(:run_via) && !Minitest.run_via[:rails]
6
- Minitest.run_via[:ruby] = true
5
+ if Minitest.respond_to?(:run_via) && !Minitest.run_via.set?
6
+ Minitest.run_via = :ruby
7
7
  end
8
8
 
9
9
  Minitest.autorun
@@ -7,7 +7,7 @@ module ActiveSupport
7
7
  @stubs = {}
8
8
  end
9
9
 
10
- def stub_object(object, method_name, return_value)
10
+ def stub_object(object, method_name, &block)
11
11
  key = [object.object_id, method_name]
12
12
 
13
13
  if stub = @stubs[key]
@@ -19,7 +19,7 @@ module ActiveSupport
19
19
  @stubs[key] = Stub.new(object, method_name, new_name)
20
20
 
21
21
  object.singleton_class.send :alias_method, new_name, method_name
22
- object.define_singleton_method(method_name) { return_value }
22
+ object.define_singleton_method(method_name, &block)
23
23
  end
24
24
 
25
25
  def unstub_all!
@@ -99,9 +99,9 @@ module ActiveSupport
99
99
  now = date_or_time.to_time.change(usec: 0)
100
100
  end
101
101
 
102
- simple_stubs.stub_object(Time, :now, now)
103
- simple_stubs.stub_object(Date, :today, now.to_date)
104
- simple_stubs.stub_object(DateTime, :now, now.to_datetime)
102
+ simple_stubs.stub_object(Time, :now) { at(now.to_i) }
103
+ simple_stubs.stub_object(Date, :today) { jd(now.to_date.jd) }
104
+ simple_stubs.stub_object(DateTime, :now) { jd(now.to_date.jd, now.hour, now.min, now.sec, Rational(now.utc_offset, 86400)) }
105
105
 
106
106
  if block_given?
107
107
  begin
@@ -428,7 +428,8 @@ module ActiveSupport
428
428
  end
429
429
 
430
430
  def freeze
431
- period; utc; time # preload instance variables before freezing
431
+ # preload instance variables before freezing
432
+ period; utc; time; to_datetime
432
433
  super
433
434
  end
434
435
 
@@ -48,8 +48,8 @@ module ActiveSupport
48
48
  }
49
49
 
50
50
  # No need to map these on Ruby 2.4+
51
- TYPE_NAMES["Fixnum"] = "integer" unless Fixnum == Integer
52
- TYPE_NAMES["Bignum"] = "integer" unless Bignum == Integer
51
+ TYPE_NAMES["Fixnum"] = "integer" unless 0.class == Integer
52
+ TYPE_NAMES["Bignum"] = "integer" unless 0.class == Integer
53
53
  end
54
54
 
55
55
  FORMATTING = {
@@ -68,7 +68,17 @@ module ActiveSupport
68
68
  "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
69
69
  "integer" => Proc.new { |integer| integer.to_i },
70
70
  "float" => Proc.new { |float| float.to_f },
71
- "decimal" => Proc.new { |number| BigDecimal(number) },
71
+ "decimal" => Proc.new do |number|
72
+ if String === number
73
+ begin
74
+ BigDecimal(number)
75
+ rescue ArgumentError
76
+ BigDecimal('0')
77
+ end
78
+ else
79
+ BigDecimal(number)
80
+ end
81
+ end,
72
82
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
73
83
  "string" => Proc.new { |string| string.to_s },
74
84
  "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2017-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -331,15 +331,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
331
331
  version: 2.2.2
332
332
  required_rubygems_version: !ruby/object:Gem::Requirement
333
333
  requirements:
334
- - - ">="
334
+ - - ">"
335
335
  - !ruby/object:Gem::Version
336
- version: '0'
336
+ version: 1.3.1
337
337
  requirements: []
338
338
  rubyforge_project:
339
- rubygems_version: 2.5.2
339
+ rubygems_version: 2.6.10
340
340
  signing_key:
341
341
  specification_version: 4
342
342
  summary: A toolkit of support libraries and Ruby core extensions extracted from the
343
343
  Rails framework.
344
344
  test_files: []
345
- has_rdoc: