sinatra 2.2.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

data/Rakefile CHANGED
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/clean'
2
4
  require 'rake/testtask'
3
5
  require 'fileutils'
4
6
  require 'date'
5
7
 
6
- task :default => :test
7
- task :spec => :test
8
+ task default: :test
9
+ task spec: :test
8
10
 
9
- CLEAN.include "**/*.rbc"
11
+ CLEAN.include '**/*.rbc'
10
12
 
11
13
  def source_version
12
- @source_version ||= File.read(File.expand_path("../VERSION", __FILE__)).strip
14
+ @source_version ||= File.read(File.expand_path('VERSION', __dir__)).strip
13
15
  end
14
16
 
15
17
  def prev_feature
@@ -17,32 +19,28 @@ def prev_feature
17
19
  end
18
20
 
19
21
  def prev_version
20
- return prev_feature + '.0' if source_version.end_with? '.0'
22
+ return "#{prev_feature}.0" if source_version.end_with? '.0'
23
+
21
24
  source_version.gsub(/\d+$/) { |s| s.to_i - 1 }
22
25
  end
23
26
 
24
27
  # SPECS ===============================================================
25
28
 
26
- task :test do
27
- ENV['LANG'] = 'C'
28
- ENV.delete 'LC_CTYPE'
29
- end
30
-
31
29
  Rake::TestTask.new(:test) do |t|
32
30
  t.test_files = FileList['test/*_test.rb']
33
31
  t.ruby_opts = ['-r rubygems'] if defined? Gem
34
- t.ruby_opts << '-I.'
35
32
  t.warning = true
36
33
  end
37
34
 
38
- Rake::TestTask.new(:"test:core") do |t|
39
- core_tests = %w[base delegator encoding extensions filter
40
- helpers mapped_error middleware radius rdoc
41
- readme request response result route_added_hook
42
- routing server settings sinatra static templates]
43
- t.test_files = core_tests.map {|n| "test/#{n}_test.rb"}
44
- t.ruby_opts = ["-r rubygems"] if defined? Gem
45
- t.ruby_opts << "-I."
35
+ Rake::TestTask.new(:'test:core') do |t|
36
+ core_tests = %w[
37
+ base delegator encoding extensions filter
38
+ helpers mapped_error middleware rdoc
39
+ readme request response result route_added_hook
40
+ routing server settings sinatra static templates
41
+ ]
42
+ t.test_files = core_tests.map { |n| "test/#{n}_test.rb" }
43
+ t.ruby_opts = ['-r rubygems'] if defined? Gem
46
44
  t.warning = true
47
45
  end
48
46
 
@@ -51,7 +49,7 @@ end
51
49
  namespace :test do
52
50
  desc 'Measures test coverage'
53
51
  task :coverage do
54
- rm_f "coverage"
52
+ rm_f 'coverage'
55
53
  ENV['COVERAGE'] = '1'
56
54
  Rake::Task['test'].invoke
57
55
  end
@@ -60,26 +58,26 @@ end
60
58
  # Website =============================================================
61
59
 
62
60
  desc 'Generate RDoc under doc/api'
63
- task 'doc' => ['doc:api']
64
- task('doc:api') { sh "yardoc -o doc/api" }
61
+ task 'doc' => ['doc:api']
62
+ task('doc:api') { sh 'yardoc -o doc/api' }
65
63
  CLEAN.include 'doc/api'
66
64
 
67
65
  # README ===============================================================
68
66
 
69
- task :add_template, [:name] do |t, args|
67
+ task :add_template, [:name] do |_t, args|
70
68
  Dir.glob('README.*') do |file|
71
69
  code = File.read(file)
72
70
  if code =~ /^===.*#{args.name.capitalize}/
73
71
  puts "Already covered in #{file}"
74
72
  else
75
- template = code[/===[^\n]*Liquid.*index\.liquid<\/tt>[^\n]*/m]
76
- if !template
77
- puts "Liquid not found in #{file}"
78
- else
73
+ template = code[%r{===[^\n]*Liquid.*index\.liquid</tt>[^\n]*}m]
74
+ if template
79
75
  puts "Adding section to #{file}"
80
76
  template = template.gsub(/Liquid/, args.name.capitalize).gsub(/liquid/, args.name.downcase)
81
77
  code.gsub! /^(\s*===.*CoffeeScript)/, "\n" << template << "\n\\1"
82
- File.open(file, "w") { |f| f << code }
78
+ File.open(file, 'w') { |f| f << code }
79
+ else
80
+ puts "Liquid not found in #{file}"
83
81
  end
84
82
  end
85
83
  end
@@ -87,29 +85,31 @@ end
87
85
 
88
86
  # Thanks in announcement ===============================================
89
87
 
90
- team = ["Ryan Tomayko", "Blake Mizerany", "Simon Rozet", "Konstantin Haase", "Zachary Scott"]
91
- desc "list of contributors"
92
- task :thanks, ['release:all', :backports] do |t, a|
93
- a.with_defaults :release => "#{prev_version}..HEAD",
94
- :backports => "#{prev_feature}.0..#{prev_feature}.x"
88
+ team = ['Ryan Tomayko', 'Blake Mizerany', 'Simon Rozet', 'Konstantin Haase', 'Zachary Scott']
89
+ desc 'list of contributors'
90
+ task :thanks, ['release:all', :backports] do |_t, a|
91
+ a.with_defaults release: "#{prev_version}..HEAD",
92
+ backports: "#{prev_feature}.0..#{prev_feature}.x"
93
+
95
94
  included = `git log --format=format:"%aN\t%s" #{a.release}`.lines.map { |l| l.force_encoding('binary') }
96
95
  excluded = `git log --format=format:"%aN\t%s" #{a.backports}`.lines.map { |l| l.force_encoding('binary') }
97
96
  commits = (included - excluded).group_by { |c| c[/^[^\t]+/] }
98
97
  authors = commits.keys.sort_by { |n| - commits[n].size } - team
99
- puts authors[0..-2].join(', ') << " and " << authors.last,
100
- "(based on commits included in #{a.release}, but not in #{a.backports})"
98
+ puts authors[0..-2].join(', ') << ' and ' << authors.last,
99
+ "(based on commits included in #{a.release}, but not in #{a.backports})"
101
100
  end
102
101
 
103
- desc "list of authors"
104
- task :authors, [:commit_range, :format, :sep] do |t, a|
105
- a.with_defaults :format => "%s (%d)", :sep => ", ", :commit_range => '--all'
102
+ desc 'list of authors'
103
+ task :authors, [:commit_range, :format, :sep] do |_t, a|
104
+ a.with_defaults format: '%s (%d)', sep: ', ', commit_range: '--all'
106
105
  authors = Hash.new(0)
107
- blake = "Blake Mizerany"
106
+ blake = 'Blake Mizerany'
108
107
  overall = 0
109
108
  mapping = {
110
- "blake.mizerany@gmail.com" => blake, "bmizerany" => blake,
111
- "a_user@mac.com" => blake, "ichverstehe" => "Harry Vangberg",
112
- "Wu Jiang (nouse)" => "Wu Jiang" }
109
+ 'blake.mizerany@gmail.com' => blake, 'bmizerany' => blake,
110
+ 'a_user@mac.com' => blake, 'ichverstehe' => 'Harry Vangberg',
111
+ 'Wu Jiang (nouse)' => 'Wu Jiang'
112
+ }
113
113
  `git shortlog -s #{a.commit_range}`.lines.map do |line|
114
114
  line = line.force_encoding 'binary' if line.respond_to? :force_encoding
115
115
  num, name = line.split("\t", 2).map(&:strip)
@@ -117,18 +117,18 @@ task :authors, [:commit_range, :format, :sep] do |t, a|
117
117
  overall += num.to_i
118
118
  end
119
119
  puts "#{overall} commits by #{authors.count} authors:"
120
- puts authors.sort_by { |n,c| -c }.map { |e| a.format % e }.join(a.sep)
120
+ puts authors.sort_by { |_n, c| -c }.map { |e| a.format % e }.join(a.sep)
121
121
  end
122
122
 
123
- desc "generates TOC"
124
- task :toc, [:readme] do |t, a|
125
- a.with_defaults :readme => 'README.md'
123
+ desc 'generates TOC'
124
+ task :toc, [:readme] do |_t, a|
125
+ a.with_defaults readme: 'README.md'
126
126
 
127
127
  def self.link(title)
128
128
  title.downcase.gsub(/(?!-)\W /, '-').gsub(' ', '-').gsub(/(?!-)\W/, '')
129
129
  end
130
130
 
131
- puts "* [Sinatra](#sinatra)"
131
+ puts '* [Sinatra](#sinatra)'
132
132
  title = Regexp.new('(?<=\* )(.*)') # so Ruby 1.8 doesn't complain
133
133
  File.binread(a.readme).scan(/^##.*/) do |line|
134
134
  puts line.gsub(/#(?=#)/, ' ').gsub('#', '*').gsub(title) { "[#{$1}](##{link($1)})" }
@@ -139,12 +139,12 @@ end
139
139
 
140
140
  if defined?(Gem)
141
141
  GEMS_AND_ROOT_DIRECTORIES = {
142
- "sinatra" => ".",
143
- "sinatra-contrib" => "./sinatra-contrib",
144
- "rack-protection" => "./rack-protection"
145
- }
142
+ 'sinatra' => '.',
143
+ 'sinatra-contrib' => './sinatra-contrib',
144
+ 'rack-protection' => './rack-protection'
145
+ }.freeze
146
146
 
147
- def package(gem, ext='')
147
+ def package(gem, ext = '')
148
148
  "pkg/#{gem}-#{source_version}" + ext
149
149
  end
150
150
 
@@ -152,12 +152,12 @@ if defined?(Gem)
152
152
  CLOBBER.include('pkg')
153
153
 
154
154
  GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
155
- file package(gem, '.gem') => ["pkg/", "#{directory + '/' + gem}.gemspec"] do |f|
155
+ file package(gem, '.gem') => ['pkg/', "#{"#{directory}/#{gem}"}.gemspec"] do |f|
156
156
  sh "cd #{directory} && gem build #{gem}.gemspec"
157
- mv directory + "/" + File.basename(f.name), f.name
157
+ mv "#{directory}/#{File.basename(f.name)}", f.name
158
158
  end
159
159
 
160
- file package(gem, '.tar.gz') => ["pkg/"] do |f|
160
+ file package(gem, '.tar.gz') => ['pkg/'] do |f|
161
161
  sh <<-SH
162
162
  git archive \
163
163
  --prefix=#{gem}-#{source_version}/ \
@@ -168,29 +168,29 @@ if defined?(Gem)
168
168
  end
169
169
 
170
170
  namespace :package do
171
- GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
171
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, _directory|
172
172
  desc "Build #{gem} packages"
173
173
  task gem => %w[.gem .tar.gz].map { |e| package(gem, e) }
174
174
  end
175
175
 
176
- desc "Build all packages"
177
- task :all => GEMS_AND_ROOT_DIRECTORIES.keys
176
+ desc 'Build all packages'
177
+ task all: GEMS_AND_ROOT_DIRECTORIES.keys
178
178
  end
179
179
 
180
180
  namespace :install do
181
- GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
181
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, _directory|
182
182
  desc "Build and install #{gem} as local gem"
183
183
  task gem => package(gem, '.gem') do
184
184
  sh "gem install #{package(gem, '.gem')}"
185
185
  end
186
186
  end
187
187
 
188
- desc "Build and install all of the gems as local gems"
189
- task :all => GEMS_AND_ROOT_DIRECTORIES.keys
188
+ desc 'Build and install all of the gems as local gems'
189
+ task all: GEMS_AND_ROOT_DIRECTORIES.keys
190
190
  end
191
191
 
192
192
  namespace :release do
193
- GEMS_AND_ROOT_DIRECTORIES.each do |gem, directory|
193
+ GEMS_AND_ROOT_DIRECTORIES.each do |gem, _directory|
194
194
  desc "Release #{gem} as a package"
195
195
  task gem => "package:#{gem}" do
196
196
  sh <<-SH
@@ -200,7 +200,7 @@ if defined?(Gem)
200
200
  end
201
201
  end
202
202
 
203
- desc "Commits the version to github repository"
203
+ desc 'Commits the version to github repository'
204
204
  task :commit_version do
205
205
  %w[
206
206
  lib/sinatra
@@ -219,7 +219,7 @@ if defined?(Gem)
219
219
  SH
220
220
  end
221
221
 
222
- desc "Release all gems as packages"
223
- task :all => [:test, :commit_version] + GEMS_AND_ROOT_DIRECTORIES.keys
222
+ desc 'Release all gems as packages'
223
+ task all: %i[test commit_version] + GEMS_AND_ROOT_DIRECTORIES.keys
224
224
  end
225
225
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 3.0.1
data/examples/chat.rb CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env ruby -I ../lib -I lib
2
- # coding: utf-8
2
+ # frozen_string_literal: true
3
+
3
4
  require_relative 'rainbows'
5
+
4
6
  require 'sinatra'
5
7
  set :server, :rainbows
6
8
  connections = []
7
9
 
8
10
  get '/' do
9
11
  halt erb(:login) unless params[:user]
10
- erb :chat, :locals => { :user => params[:user].gsub(/\W/, '') }
12
+ erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
11
13
  end
12
14
 
13
- get '/stream', :provides => 'text/event-stream' do
15
+ get '/stream', provides: 'text/event-stream' do
14
16
  stream :keep_open do |out|
15
17
  connections << out
16
18
  out.callback { connections.delete(out) }
data/examples/rainbows.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rainbows'
2
4
 
3
5
  module Rack
@@ -8,7 +10,7 @@ module Rack
8
10
  listeners: ["#{options[:Host]}:#{options[:Port]}"],
9
11
  worker_processes: 1,
10
12
  timeout: 30,
11
- config_file: ::File.expand_path('rainbows.conf', __dir__),
13
+ config_file: ::File.expand_path('rainbows.conf', __dir__)
12
14
  }
13
15
 
14
16
  ::Rainbows::HttpServer.new(app, rainbows_options).start.join
data/examples/simple.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby -I ../lib -I lib
2
+ # frozen_string_literal: true
3
+
2
4
  require 'sinatra'
3
5
  get('/') { 'this is a simple app' }
data/examples/stream.ru CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this example does *not* work properly with WEBrick
2
4
  #
3
5
  # run *one* of these: