sinatra 2.2.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

@@ -1,11 +1,4 @@
1
1
  # frozen_string_literal: true
2
- $stderr.puts <<EOF if !Hash.method_defined?(:slice) && !$LOAD_PATH.grep(%r{gems/activesupport}).empty? && ENV['SINATRA_ACTIVESUPPORT_WARNING'] != 'false'
3
- WARNING: If you plan to load any of ActiveSupport's core extensions to Hash, be
4
- sure to do so *before* loading Sinatra::Application or Sinatra::Base. If not,
5
- you may disregard this warning.
6
-
7
- Set SINATRA_ACTIVESUPPORT_WARNING=false in the environment to hide this warning.
8
- EOF
9
2
 
10
3
  module Sinatra
11
4
  # A poor man's ActiveSupport::HashWithIndifferentAccess, with all the Rails-y
@@ -28,7 +21,8 @@ module Sinatra
28
21
  # writing interface (calling e.g. <tt>[]=</tt>, <tt>merge</tt>). This mapping
29
22
  # belongs to the public interface. For example, given:
30
23
  #
31
- # hash = Sinatra::IndifferentHash.new(:a=>1)
24
+ # hash = Sinatra::IndifferentHash.new
25
+ # hash[:a] = 1
32
26
  #
33
27
  # You are guaranteed that the key is returned as a string:
34
28
  #
@@ -36,7 +30,8 @@ module Sinatra
36
30
  #
37
31
  # Technically other types of keys are accepted:
38
32
  #
39
- # hash = Sinatra::IndifferentHash.new(:a=>1)
33
+ # hash = Sinatra::IndifferentHash
34
+ # hash[:a] = 1
40
35
  # hash[0] = 0
41
36
  # hash # => { "a"=>1, 0=>0 }
42
37
  #
@@ -86,7 +81,7 @@ module Sinatra
86
81
  super(convert_key(key), convert_value(value))
87
82
  end
88
83
 
89
- alias_method :store, :[]=
84
+ alias store []=
90
85
 
91
86
  def key(value)
92
87
  super(convert_value(value))
@@ -96,35 +91,36 @@ module Sinatra
96
91
  super(convert_key(key))
97
92
  end
98
93
 
99
- alias_method :has_key?, :key?
100
- alias_method :include?, :key?
101
- alias_method :member?, :key?
94
+ alias has_key? key?
95
+ alias include? key?
96
+ alias member? key?
102
97
 
103
98
  def value?(value)
104
99
  super(convert_value(value))
105
100
  end
106
101
 
107
- alias_method :has_value?, :value?
102
+ alias has_value? value?
108
103
 
109
104
  def delete(key)
110
105
  super(convert_key(key))
111
106
  end
112
107
 
108
+ # Added in Ruby 2.3
113
109
  def dig(key, *other_keys)
114
110
  super(convert_key(key), *other_keys)
115
- end if method_defined?(:dig) # Added in Ruby 2.3
111
+ end
116
112
 
117
113
  def fetch_values(*keys)
118
114
  keys.map!(&method(:convert_key))
119
115
 
120
116
  super(*keys)
121
- end if method_defined?(:fetch_values) # Added in Ruby 2.3
117
+ end
122
118
 
123
119
  def slice(*keys)
124
120
  keys.map!(&method(:convert_key))
125
121
 
126
122
  self.class[super(*keys)]
127
- end if method_defined?(:slice) # Added in Ruby 2.5
123
+ end
128
124
 
129
125
  def values_at(*keys)
130
126
  keys.map!(&method(:convert_key))
@@ -148,7 +144,7 @@ module Sinatra
148
144
  self
149
145
  end
150
146
 
151
- alias_method :update, :merge!
147
+ alias update merge!
152
148
 
153
149
  def merge(*other_hashes, &block)
154
150
  dup.merge!(*other_hashes, &block)
@@ -158,41 +154,45 @@ module Sinatra
158
154
  super(other_hash.is_a?(self.class) ? other_hash : self.class[other_hash])
159
155
  end
160
156
 
161
- if method_defined?(:transform_values!) # Added in Ruby 2.4
162
- def transform_values(&block)
163
- dup.transform_values!(&block)
164
- end
157
+ def transform_values(&block)
158
+ dup.transform_values!(&block)
159
+ end
165
160
 
166
- def transform_values!
167
- super
168
- super(&method(:convert_value))
169
- end
161
+ def transform_values!
162
+ super
163
+ super(&method(:convert_value))
170
164
  end
171
165
 
172
- if method_defined?(:transform_keys!) # Added in Ruby 2.5
173
- def transform_keys(&block)
174
- dup.transform_keys!(&block)
175
- end
166
+ def transform_keys(&block)
167
+ dup.transform_keys!(&block)
168
+ end
176
169
 
177
- def transform_keys!
178
- super
179
- super(&method(:convert_key))
180
- end
170
+ def transform_keys!
171
+ super
172
+ super(&method(:convert_key))
181
173
  end
182
174
 
183
175
  def select(*args, &block)
184
176
  return to_enum(:select) unless block_given?
177
+
185
178
  dup.tap { |hash| hash.select!(*args, &block) }
186
179
  end
187
180
 
188
181
  def reject(*args, &block)
189
182
  return to_enum(:reject) unless block_given?
183
+
190
184
  dup.tap { |hash| hash.reject!(*args, &block) }
191
185
  end
192
186
 
193
187
  def compact
194
188
  dup.tap(&:compact!)
195
- end if method_defined?(:compact) # Added in Ruby 2.4
189
+ end
190
+
191
+ def except(*keys)
192
+ keys.map!(&method(:convert_key))
193
+
194
+ super(*keys)
195
+ end if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0")
196
196
 
197
197
  private
198
198
 
data/lib/sinatra/main.rb CHANGED
@@ -1,47 +1,49 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sinatra
2
- ParamsConfig = {}
4
+ PARAMS_CONFIG = {}
3
5
 
4
6
  if ARGV.any?
5
7
  require 'optparse'
6
- parser = OptionParser.new { |op|
7
- op.on('-p port', 'set the port (default is 4567)') { |val| ParamsConfig[:port] = Integer(val) }
8
- op.on('-s server', 'specify rack server/handler') { |val| ParamsConfig[:server] = val }
9
- op.on('-q', 'turn on quiet mode (default is off)') { ParamsConfig[:quiet] = true }
10
- op.on('-x', 'turn on the mutex lock (default is off)') { ParamsConfig[:lock] = true }
8
+ parser = OptionParser.new do |op|
9
+ op.on('-p port', 'set the port (default is 4567)') { |val| PARAMS_CONFIG[:port] = Integer(val) }
10
+ op.on('-s server', 'specify rack server/handler') { |val| PARAMS_CONFIG[:server] = val }
11
+ op.on('-q', 'turn on quiet mode (default is off)') { PARAMS_CONFIG[:quiet] = true }
12
+ op.on('-x', 'turn on the mutex lock (default is off)') { PARAMS_CONFIG[:lock] = true }
11
13
  op.on('-e env', 'set the environment (default is development)') do |val|
12
14
  ENV['RACK_ENV'] = val
13
- ParamsConfig[:environment] = val.to_sym
15
+ PARAMS_CONFIG[:environment] = val.to_sym
14
16
  end
15
17
  op.on('-o addr', "set the host (default is (env == 'development' ? 'localhost' : '0.0.0.0'))") do |val|
16
- ParamsConfig[:bind] = val
18
+ PARAMS_CONFIG[:bind] = val
17
19
  end
18
- }
20
+ end
19
21
  begin
20
22
  parser.parse!(ARGV.dup)
21
- rescue => evar
22
- ParamsConfig[:optparse_error] = evar
23
+ rescue StandardError => e
24
+ PARAMS_CONFIG[:optparse_error] = e
23
25
  end
24
26
  end
25
27
 
26
28
  require 'sinatra/base'
27
29
 
28
30
  class Application < Base
29
-
30
31
  # we assume that the first file that requires 'sinatra' is the
31
32
  # app_file. all other path related options are calculated based
32
33
  # on this path by default.
33
34
  set :app_file, caller_files.first || $0
34
35
 
35
- set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
36
+ set :run, proc { File.expand_path($0) == File.expand_path(app_file) }
36
37
 
37
38
  if run? && ARGV.any?
38
- error = ParamsConfig.delete(:optparse_error)
39
+ error = PARAMS_CONFIG.delete(:optparse_error)
39
40
  raise error if error
40
- ParamsConfig.each { |k, v| set k, v }
41
+
42
+ PARAMS_CONFIG.each { |k, v| set k, v }
41
43
  end
42
44
  end
43
45
 
44
- remove_const(:ParamsConfig)
46
+ remove_const(:PARAMS_CONFIG)
45
47
  at_exit { Application.run! if $!.nil? && Application.run? }
46
48
  end
47
49
 
@@ -12,6 +12,7 @@ module Sinatra
12
12
  class ShowExceptions < Rack::ShowExceptions
13
13
  @@eats_errors = Object.new
14
14
  def @@eats_errors.flush(*) end
15
+
15
16
  def @@eats_errors.puts(*) end
16
17
 
17
18
  def initialize(app)
@@ -21,23 +22,24 @@ module Sinatra
21
22
  def call(env)
22
23
  @app.call(env)
23
24
  rescue Exception => e
24
- errors, env["rack.errors"] = env["rack.errors"], @@eats_errors
25
+ errors = env['rack.errors']
26
+ env['rack.errors'] = @@eats_errors
25
27
 
26
28
  if prefers_plain_text?(env)
27
- content_type = "text/plain"
29
+ content_type = 'text/plain'
28
30
  body = dump_exception(e)
29
31
  else
30
- content_type = "text/html"
32
+ content_type = 'text/html'
31
33
  body = pretty(env, e)
32
34
  end
33
35
 
34
- env["rack.errors"] = errors
36
+ env['rack.errors'] = errors
35
37
 
36
38
  [
37
39
  500,
38
40
  {
39
- "Content-Type" => content_type,
40
- "Content-Length" => body.bytesize.to_s
41
+ 'Content-Type' => content_type,
42
+ 'Content-Length' => body.bytesize.to_s
41
43
  },
42
44
  [body]
43
45
  ]
@@ -49,27 +51,27 @@ module Sinatra
49
51
 
50
52
  private
51
53
 
52
- def bad_request?(e)
53
- Sinatra::BadRequest === e
54
+ def bad_request?(exception)
55
+ Sinatra::BadRequest === exception
54
56
  end
55
57
 
56
58
  def prefers_plain_text?(env)
57
- !(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
58
- [/curl/].index { |item| item =~ env["HTTP_USER_AGENT"] }
59
+ Request.new(env).preferred_type('text/plain', 'text/html') != 'text/html' &&
60
+ [/curl/].index { |item| item =~ env['HTTP_USER_AGENT'] }
59
61
  end
60
62
 
61
63
  def frame_class(frame)
62
64
  if frame.filename =~ %r{lib/sinatra.*\.rb}
63
- "framework"
65
+ 'framework'
64
66
  elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
65
67
  frame.filename =~ %r{/bin/(\w+)\z}
66
- "system"
68
+ 'system'
67
69
  else
68
- "app"
70
+ 'app'
69
71
  end
70
72
  end
71
73
 
72
- TEMPLATE = ERB.new <<-HTML # :nodoc:
74
+ TEMPLATE = ERB.new <<-HTML # :nodoc:
73
75
  <!DOCTYPE html>
74
76
  <html>
75
77
  <head>
@@ -357,6 +359,6 @@ enabled the <code>show_exceptions</code> setting.</p>
357
359
  </div> <!-- /WRAP -->
358
360
  </body>
359
361
  </html>
360
- HTML
362
+ HTML
361
363
  end
362
364
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sinatra
2
- VERSION = '2.2.3'
4
+ VERSION = '3.2.0'
3
5
  end
data/lib/sinatra.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/main'
2
4
 
3
5
  enable :inline_templates
data/sinatra.gemspec CHANGED
@@ -1,49 +1,52 @@
1
- version = File.read(File.expand_path("../VERSION", __FILE__)).strip
1
+ # frozen_string_literal: true
2
+
3
+ version = File.read(File.expand_path('VERSION', __dir__)).strip
2
4
 
3
5
  Gem::Specification.new 'sinatra', version do |s|
4
- s.description = "Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort."
5
- s.summary = "Classy web-development dressed in a DSL"
6
- s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet", "Konstantin Haase"]
7
- s.email = "sinatrarb@googlegroups.com"
8
- s.homepage = "http://sinatrarb.com/"
6
+ s.description = 'Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort.'
7
+ s.summary = 'Classy web-development dressed in a DSL'
8
+ s.authors = ['Blake Mizerany', 'Ryan Tomayko', 'Simon Rozet', 'Konstantin Haase']
9
+ s.email = 'sinatrarb@googlegroups.com'
10
+ s.homepage = 'http://sinatrarb.com/'
9
11
  s.license = 'MIT'
10
12
  s.files = Dir['README*.md', 'lib/**/*', 'examples/*'] + [
11
- ".yardopts",
12
- "AUTHORS.md",
13
- "CHANGELOG.md",
14
- "CONTRIBUTING.md",
15
- "Gemfile",
16
- "LICENSE",
17
- "MAINTENANCE.md",
18
- "Rakefile",
19
- "SECURITY.md",
20
- "sinatra.gemspec",
21
- "VERSION"]
13
+ '.yardopts',
14
+ 'AUTHORS.md',
15
+ 'CHANGELOG.md',
16
+ 'CONTRIBUTING.md',
17
+ 'Gemfile',
18
+ 'LICENSE',
19
+ 'MAINTENANCE.md',
20
+ 'Rakefile',
21
+ 'SECURITY.md',
22
+ 'sinatra.gemspec',
23
+ 'VERSION'
24
+ ]
22
25
  s.extra_rdoc_files = %w[README.md LICENSE]
23
26
  s.rdoc_options = %w[--line-numbers --title Sinatra --main README.rdoc --encoding=UTF-8]
24
27
 
25
- if s.respond_to?(:metadata)
26
- s.metadata = {
27
- 'source_code_uri' => 'https://github.com/sinatra/sinatra',
28
- 'changelog_uri' => 'https://github.com/sinatra/sinatra/blob/master/CHANGELOG.md',
29
- 'homepage_uri' => 'http://sinatrarb.com/',
30
- 'bug_tracker_uri' => 'https://github.com/sinatra/sinatra/issues',
31
- 'mailing_list_uri' => 'http://groups.google.com/group/sinatrarb',
32
- 'documentation_uri' => 'https://www.rubydoc.info/gems/sinatra'
33
- }
34
- else
35
- raise <<-EOF
28
+ unless s.respond_to?(:metadata)
29
+ raise <<-WARN
36
30
  RubyGems 2.0 or newer is required to protect against public gem pushes. You can update your rubygems version by running:
37
31
  gem install rubygems-update
38
32
  update_rubygems:
39
33
  gem update --system
40
- EOF
34
+ WARN
41
35
  end
42
36
 
43
- s.required_ruby_version = '>= 2.3.0'
37
+ s.metadata = {
38
+ 'source_code_uri' => 'https://github.com/sinatra/sinatra',
39
+ 'changelog_uri' => 'https://github.com/sinatra/sinatra/blob/main/CHANGELOG.md',
40
+ 'homepage_uri' => 'http://sinatrarb.com/',
41
+ 'bug_tracker_uri' => 'https://github.com/sinatra/sinatra/issues',
42
+ 'mailing_list_uri' => 'http://groups.google.com/group/sinatrarb',
43
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/sinatra'
44
+ }
44
45
 
45
- s.add_dependency 'rack', '~> 2.2'
46
- s.add_dependency 'tilt', '~> 2.0'
46
+ s.required_ruby_version = '>= 2.6.0'
47
+
48
+ s.add_dependency 'mustermann', '~> 3.0'
49
+ s.add_dependency 'rack', '~> 2.2', '>= 2.2.4'
47
50
  s.add_dependency 'rack-protection', version
48
- s.add_dependency 'mustermann', '~> 2.0'
51
+ s.add_dependency 'tilt', '~> 2.0'
49
52
  end
metadata CHANGED
@@ -1,62 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
8
8
  - Ryan Tomayko
9
9
  - Simon Rozet
10
10
  - Konstantin Haase
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-12-16 00:00:00.000000000 Z
14
+ date: 2023-12-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: rack
17
+ name: mustermann
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.2'
22
+ version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '2.2'
29
+ version: '3.0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: tilt
31
+ name: rack
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: '2.0'
36
+ version: '2.2'
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.2.4
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
44
  - - "~>"
42
45
  - !ruby/object:Gem::Version
43
- version: '2.0'
46
+ version: '2.2'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.2.4
44
50
  - !ruby/object:Gem::Dependency
45
51
  name: rack-protection
46
52
  requirement: !ruby/object:Gem::Requirement
47
53
  requirements:
48
54
  - - '='
49
55
  - !ruby/object:Gem::Version
50
- version: 2.2.4
56
+ version: 3.2.0
51
57
  type: :runtime
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
54
60
  requirements:
55
61
  - - '='
56
62
  - !ruby/object:Gem::Version
57
- version: 2.2.4
63
+ version: 3.2.0
58
64
  - !ruby/object:Gem::Dependency
59
- name: mustermann
65
+ name: tilt
60
66
  requirement: !ruby/object:Gem::Requirement
61
67
  requirements:
62
68
  - - "~>"
@@ -85,24 +91,12 @@ files:
85
91
  - Gemfile
86
92
  - LICENSE
87
93
  - MAINTENANCE.md
88
- - README.de.md
89
- - README.es.md
90
- - README.fr.md
91
- - README.hu.md
92
- - README.ja.md
93
- - README.ko.md
94
- - README.malayalam.md
95
94
  - README.md
96
- - README.pt-br.md
97
- - README.pt-pt.md
98
- - README.ru.md
99
- - README.zh.md
100
95
  - Rakefile
101
96
  - SECURITY.md
102
97
  - VERSION
103
98
  - examples/chat.rb
104
- - examples/rainbows.conf
105
- - examples/rainbows.rb
99
+ - examples/lifecycle_events.rb
106
100
  - examples/simple.rb
107
101
  - examples/stream.ru
108
102
  - lib/sinatra.rb
@@ -119,12 +113,12 @@ licenses:
119
113
  - MIT
120
114
  metadata:
121
115
  source_code_uri: https://github.com/sinatra/sinatra
122
- changelog_uri: https://github.com/sinatra/sinatra/blob/master/CHANGELOG.md
116
+ changelog_uri: https://github.com/sinatra/sinatra/blob/main/CHANGELOG.md
123
117
  homepage_uri: http://sinatrarb.com/
124
118
  bug_tracker_uri: https://github.com/sinatra/sinatra/issues
125
119
  mailing_list_uri: http://groups.google.com/group/sinatrarb
126
120
  documentation_uri: https://www.rubydoc.info/gems/sinatra
127
- post_install_message:
121
+ post_install_message:
128
122
  rdoc_options:
129
123
  - "--line-numbers"
130
124
  - "--title"
@@ -138,16 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
132
  requirements:
139
133
  - - ">="
140
134
  - !ruby/object:Gem::Version
141
- version: 2.3.0
135
+ version: 2.6.0
142
136
  required_rubygems_version: !ruby/object:Gem::Requirement
143
137
  requirements:
144
138
  - - ">="
145
139
  - !ruby/object:Gem::Version
146
140
  version: '0'
147
141
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.6.3
150
- signing_key:
142
+ rubygems_version: 3.5.3
143
+ signing_key:
151
144
  specification_version: 4
152
145
  summary: Classy web-development dressed in a DSL
153
146
  test_files: []