Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set 2.6 as minimum ruby version for Sinatra 3 #1699

Merged
merged 5 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
# TODO: Add jruby if something like allow_failures will be implemented on Actions.
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', head]
ruby: [2.6, 2.7, '3.0', head]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
6 changes: 3 additions & 3 deletions README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -3082,9 +3082,9 @@ thin --threaded start
Die folgenden Versionen werden offiziell unterstützt:

<dl>
<dt>Ruby 2.3</dt>
<dt>Ruby 2.6</dt>
<dd>
2.3 wird vollständig unterstützt. Es gibt derzeit keine Pläne die
2.6 wird vollständig unterstützt. Es gibt derzeit keine Pläne die
offizielle Unterstützung zu beenden
</dd>

Expand All @@ -3103,7 +3103,7 @@ Die folgenden Versionen werden offiziell unterstützt:
</dd>
</dl>

Versionen vor Ruby 2.2.2 werden ab Sinatra 2.0 nicht länger unterstützt.
Versionen vor Ruby 2.6 werden ab Sinatra 3.0 nicht länger unterstützt.

Nachfolgende Ruby-Versionen werden regelmäßig auf Unterstützung geprüft.

Expand Down
6 changes: 3 additions & 3 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -3075,9 +3075,9 @@ rainbows -c rainbows.conf
Las siguientes versiones de Ruby son soportadas oficialmente:

<dl>
<dt>Ruby 2.3</dt>
<dt>Ruby 2.6</dt>
<dd>
2.3 Es totalmente compatible y recomendado. Actualmente no hay planes
2.6 Es totalmente compatible y recomendado. Actualmente no hay planes
soltar el apoyo oficial para ello.
</dd>

Expand All @@ -3095,7 +3095,7 @@ Las siguientes versiones de Ruby son soportadas oficialmente:
</dd>
</dl>

Las versiones de Ruby anteriores a 2.2.2 ya no son compatibles con Sinatra 2.0 .
Las versiones de Ruby anteriores a 2.6 ya no son compatibles con Sinatra 3.0 .

Siempre le prestamos atención a las nuevas versiones de Ruby.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3047,9 +3047,9 @@ rainbows -c rainbows.conf

The following Ruby versions are officially supported:
<dl>
<dt>Ruby 2.3</dt>
<dt>Ruby 2.6</dt>
<dd>
2.3 is fully supported and recommended. There are currently no plans to
2.6 is fully supported and recommended. There are currently no plans to
drop official support for it.
</dd>

Expand All @@ -3067,7 +3067,7 @@ The following Ruby versions are officially supported:
</dd>
</dl>

Versions of Ruby before 2.3 are no longer supported as of Sinatra 2.1.0.
Versions of Ruby before 2.6 are no longer supported as of Sinatra 3.0.0.

We also keep an eye on upcoming Ruby versions.

Expand Down
6 changes: 3 additions & 3 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -3051,9 +3051,9 @@ thin --threaded start

Следующие версии Ruby официально поддерживаются:
<dl>
<dt>Ruby 2.3</dt>
<dt>Ruby 2.6</dt>
<dd>
Версия 2.3 полностью поддерживается и рекомендуется. В настоящее время нет
Версия 2.6 полностью поддерживается и рекомендуется. В настоящее время нет
планов отказаться от официальной поддержки.
</dd>

Expand All @@ -3071,7 +3071,7 @@ thin --threaded start
</dd>
</dl>

Версии Ruby ниже 2.2.2 более не поддерживаются в Sinatra 2.0.
Версии Ruby ниже 2.6 более не поддерживаются в Sinatra 3.0.

Мы также следим за предстоящими к выходу версиями Ruby.

Expand Down
41 changes: 15 additions & 26 deletions lib/sinatra/indifferent_hash.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# frozen_string_literal: true
$stderr.puts <<EOF if !Hash.method_defined?(:slice) && !$LOAD_PATH.grep(%r{gems/activesupport}).empty? && ENV['SINATRA_ACTIVESUPPORT_WARNING'] != 'false'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash#slice was added in Ruby 2.5 so this if is going to be false always.

WARNING: If you plan to load any of ActiveSupport's core extensions to Hash, be
sure to do so *before* loading Sinatra::Application or Sinatra::Base. If not,
you may disregard this warning.

Set SINATRA_ACTIVESUPPORT_WARNING=false in the environment to hide this warning.
EOF

module Sinatra
# A poor man's ActiveSupport::HashWithIndifferentAccess, with all the Rails-y
Expand Down Expand Up @@ -112,19 +105,19 @@ def delete(key)

def dig(key, *other_keys)
super(convert_key(key), *other_keys)
end if method_defined?(:dig) # Added in Ruby 2.3
end

def fetch_values(*keys)
keys.map!(&method(:convert_key))

super(*keys)
end if method_defined?(:fetch_values) # Added in Ruby 2.3
end

def slice(*keys)
keys.map!(&method(:convert_key))

self.class[super(*keys)]
end if method_defined?(:slice) # Added in Ruby 2.5
end

def values_at(*keys)
keys.map!(&method(:convert_key))
Expand Down Expand Up @@ -158,26 +151,22 @@ def replace(other_hash)
super(other_hash.is_a?(self.class) ? other_hash : self.class[other_hash])
end

if method_defined?(:transform_values!) # Added in Ruby 2.4
def transform_values(&block)
dup.transform_values!(&block)
end
def transform_values(&block)
dup.transform_values!(&block)
end

def transform_values!
super
super(&method(:convert_value))
end
def transform_values!
super
super(&method(:convert_value))
end

if method_defined?(:transform_keys!) # Added in Ruby 2.5
def transform_keys(&block)
dup.transform_keys!(&block)
end
def transform_keys(&block)
dup.transform_keys!(&block)
end

def transform_keys!
super
super(&method(:convert_key))
end
def transform_keys!
super
super(&method(:convert_key))
end

private
Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/sinatra-contrib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can
EOF
end

s.required_ruby_version = '>= 2.3.0'
s.required_ruby_version = '>= 2.6.0'

s.add_dependency "sinatra", version
s.add_dependency "mustermann", "~> 1.0"
Expand Down
2 changes: 1 addition & 1 deletion sinatra.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can
EOF
end

s.required_ruby_version = '>= 2.3.0'
s.required_ruby_version = '>= 2.6.0'

s.add_dependency 'rack', '~> 2.2'
s.add_dependency 'tilt', '~> 2.0'
Expand Down
22 changes: 0 additions & 22 deletions test/indifferent_hash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#
require 'minitest/autorun' unless defined?(Minitest)

# Suppress the ActiveSupport warning when this test is executed independently,
# outside of the full suite, on older Rubies.
ENV['SINATRA_ACTIVESUPPORT_WARNING'] = 'false'

require_relative '../lib/sinatra/indifferent_hash'

class TestIndifferentHashBasics < Minitest::Test
Expand Down Expand Up @@ -69,10 +65,6 @@ def test_merge!
end

class TestIndifferentHash < Minitest::Test
def skip_if_lacking(meth)
skip "Hash##{meth} not supported on this Ruby" unless Hash.method_defined?(meth)
end

def setup
@hash = Sinatra::IndifferentHash[:a=>:a, ?b=>:b, 3=>3,
:simple_nested=>{ :a=>:a, ?b=>:b },
Expand Down Expand Up @@ -158,8 +150,6 @@ def test_delete
end

def test_dig
skip_if_lacking :dig

assert_equal :a, @hash.dig(:a)
assert_equal :b, @hash.dig(?b)
assert_nil @hash.dig(:d)
Expand All @@ -174,8 +164,6 @@ def test_dig
end

def test_slice
skip_if_lacking :slice

assert_equal Sinatra::IndifferentHash[a: :a], @hash.slice(:a)
assert_equal Sinatra::IndifferentHash[b: :b], @hash.slice(?b)
assert_equal Sinatra::IndifferentHash[3 => 3], @hash.slice(3)
Expand All @@ -186,8 +174,6 @@ def test_slice
end

def test_fetch_values
skip_if_lacking :fetch_values

assert_raises(KeyError) { @hash.fetch_values(3, :d) }
assert_equal [:a, :b, 3, ?D], @hash.fetch_values(:a, ?b, 3, :d) { |k| k.upcase }
end
Expand Down Expand Up @@ -225,16 +211,12 @@ def test_replace
end

def test_transform_values!
skip_if_lacking :transform_values!

@hash.transform_values! { |v| v.is_a?(Hash) ? Hash[v.to_a] : v }

assert_instance_of Sinatra::IndifferentHash, @hash[:simple_nested]
end

def test_transform_values
skip_if_lacking :transform_values

hash2 = @hash.transform_values { |v| v.respond_to?(:upcase) ? v.upcase : v }

refute_equal @hash, hash2
Expand All @@ -243,17 +225,13 @@ def test_transform_values
end

def test_transform_keys!
skip_if_lacking :transform_keys!

@hash.transform_keys! { |k| k.respond_to?(:to_sym) ? k.to_sym : k }

assert_equal :a, @hash[:a]
assert_equal :a, @hash[?a]
end

def test_transform_keys
skip_if_lacking :transform_keys

hash2 = @hash.transform_keys { |k| k.respond_to?(:upcase) ? k.upcase : k }

refute_equal @hash, hash2
Expand Down