Skip to content

Commit

Permalink
Merge pull request #442 from maclover7/jm-ruby-24
Browse files Browse the repository at this point in the history
[Backport] Fixnum and Bignum are deprecated on Ruby trunk
  • Loading branch information
schneems authored Dec 19, 2016
2 parents 99b3eb2 + d47639f commit a20f35c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rvm:
- 2.1
- 2.2
- 2.3.1
- 2.4.0-rc1

matrix:
include:
Expand Down
1 change: 1 addition & 0 deletions bin/sprockets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
$VERBOSE = nil

require 'sprockets'
require 'optparse'
Expand Down
18 changes: 12 additions & 6 deletions lib/sprockets/digest_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ def detect_digest_class(bytes)
digest << 'Symbol'.freeze
digest << val.to_s
},
Fixnum => ->(val, digest) {
digest << 'Fixnum'.freeze
digest << val.to_s
},
Bignum => ->(val, digest) {
digest << 'Bignum'.freeze
Integer => ->(val, digest) {
digest << 'Integer'.freeze
digest << val.to_s
},
Array => ->(val, digest) {
Expand All @@ -73,6 +69,16 @@ def detect_digest_class(bytes)
digest << val.name
},
}
if 0.class != Integer # Ruby < 2.4
ADD_VALUE_TO_DIGEST[Fixnum] = ->(val, digest) {
digest << 'Integer'.freeze
digest << val.to_s
}
ADD_VALUE_TO_DIGEST[Bignum] = ->(val, digest) {
digest << 'Integer'.freeze
digest << val.to_s
}
end
ADD_VALUE_TO_DIGEST.default_proc = ->(_, val) {
raise TypeError, "couldn't digest #{ val }"
}
Expand Down
4 changes: 1 addition & 3 deletions lib/sprockets/processor_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ def processors_cache_keys(processors)
VALID_METADATA_VALUE_TYPES = Set.new([
String,
Symbol,
Fixnum,
Bignum,
TrueClass,
FalseClass,
NilClass
]).freeze
] + (0.class == Integer ? [Integer] : [Bignum, Fixnum])).freeze

# Internal: Set of all nested compound metadata types that can nest values.
VALID_METADATA_COMPOUND_TYPES = Set.new([
Expand Down
12 changes: 8 additions & 4 deletions lib/sprockets/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ module Utils
#
# Returns false if .dup would raise a TypeError, otherwise true.
def duplicable?(obj)
case obj
when NilClass, FalseClass, TrueClass, Symbol, Numeric
false
else
if RUBY_VERSION >= "2.4.0"
true
else
case obj
when NilClass, FalseClass, TrueClass, Symbol, Numeric
false
else
true
end
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/test_digest_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def test_digest
assert_equal "9bda381dac87b1c16b04f996abb623f43f1cdb89ce8be7dda3f67319dc440bc5", hexdigest(nil)
assert_equal "92de503a8b413365fc38050c7dd4bacf28b0f705e744dacebcaa89f2032dcd67", hexdigest(true)
assert_equal "bdfd64a7c8febcc3b0b8fb05d60c8e2a4cb6b8c081fcba20db1c9778e9beaf89", hexdigest(false)
assert_equal "0d4af38194cb7dc915a75b04926886f6753ffc5b4f54513adfc582fdf3642e8c", hexdigest(42)
assert_equal "abed5dfa575e89eb850242440d64c316071f76de0db48dd8d416f4aa5ece6afd", hexdigest(2 ** 128)
assert_equal "291e87109f89e59ad717aebe4ffc9657c700e74da45db789ecd19d6b797baee2", hexdigest(42)
assert_equal "d1312b90a6258e9bda7d10e5e1ab1468d92786eca72a65b5ab077169e36bcb1e", hexdigest(2 ** 128)
assert_equal "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", hexdigest("foo")
assert_equal "dea6712e86478d2ee22a35a8c5ac9627e7cbc5ce2407a7da7c645fea2434fe9b", hexdigest(:foo)
assert_equal "f0cf39d0be3efbb6f86ac2404100ff7e055c17ded946a06808d66f89ca03a811", hexdigest([])
assert_equal "ed98cc300019b22ca15e7cd5934028a79e7af4c75f7eeea810f43a3a4353a04d", hexdigest(["foo"])
assert_equal "54edcfe382f4abaa9ebe93efa9977b05b786c9058496609797989b7fdf8208d4", hexdigest({"foo" => "bar"})
assert_equal "62427aa539a0b78e90fd710dc0e15f2960771ba44214b5d41d4a93a8b2940a38", hexdigest({"foo" => "baz"})
assert_equal "905e6cc86eccb1849ae6c1e0bb01b96fedb3e341ad3d60f828e93e9b5e469a4f", hexdigest([[:foo, 1]])
assert_equal "9500d3562922431a8ccce61bd510d341ca8d61cf6b6e5ae620e7b1598436ed73", hexdigest([{:foo => 1}])
assert_equal "b6054efd9929004bdd0a1c09eb2d12961325396da749143def3e9a4050aa703e", hexdigest([[:foo, 1]])
assert_equal "79a19ffe41ecebd5dc35e95363e0b4aa79b139a22bc650384df57eb09842f099", hexdigest([{:foo => 1}])
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest("foo".force_encoding('UTF-8').encoding)

assert_raises(TypeError) do
Expand Down
19 changes: 18 additions & 1 deletion test/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
class TestUtils < MiniTest::Test
include Sprockets::Utils

def test_duplicable
def test_duplicable_pre_ruby_2_4
skip if RUBY_VERSION >= "2.4"

objs = [nil, true, false, 1, "foo", :foo, [], {}]
objs.each do |obj|
begin
obj.dup
rescue TypeError
refute duplicable?(obj), "can't dup: #{obj.inspect}"
else
assert duplicable?(obj), "can dup: #{obj.inspect}"
end
end
end

def test_duplicable_post_ruby_2_4
skip if RUBY_VERSION < "2.4"

objs = [nil, true, false, 1, "foo", :foo, [], {}]
objs.each do |obj|
begin
Expand Down

0 comments on commit a20f35c

Please sign in to comment.