scorched 0.21 → 0.22
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.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGES.md +5 -1
- data/docs/02_fundamentals/04_requests_and_responses.md +1 -1
- data/examples/file_upload.ru +4 -7
- data/examples/less_simple.ru +46 -0
- data/examples/rails_style_routing.ru +1 -0
- data/examples/simple.ru +9 -4
- data/lib/scorched/controller.rb +6 -3
- data/lib/scorched/version.rb +1 -1
- data/scorched.gemspec +1 -1
- metadata +5 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f796c21d65c86f604be0aea1a3dbcecdff2abe0
|
4
|
+
data.tar.gz: 7c192c6f91c1e00fd97cb32865b5c8f610cc1916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506421a43fcc2fa091978a349d910b3e016696b437ab26aaca12e258219455ba38f9a3483e99f83970df030c649ce2965598eff7c885b5185adfad7dc06d66b9
|
7
|
+
data.tar.gz: cc0b1638943da206f905d46834ae0f2df3151459a1de60ff537028f3fd69f5732f57ae8d8e921bed302d639e7047a4239e9a5aa42edd4d181900f27fa628be2a
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--protected lib/**/*.rb - README.md TODO.md LICENSE
|
data/CHANGES.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
-
_Note that Scorched is yet to reach a v1.0 release. This means breaking changes may still be made. If upgrading
|
4
|
+
_Note that Scorched is yet to reach a v1.0 release. This means breaking changes may still be made. If upgrading the version of Scorched for your project, review this changelog carefully._
|
5
|
+
|
6
|
+
### v0.22
|
7
|
+
* The `redirect` method now passes the given URL through `absolute`.
|
8
|
+
* The error page filter now always runs at the end-point controller so `:show_http_error_pages` behaves as expected when overriden in sub-controllers.
|
5
9
|
|
6
10
|
### v0.21
|
7
11
|
* Named captures have changed again. The values are now passed as arguments to route proc's in favor of using the new `captures` convenience method for accessing named arguments as a hash.
|
@@ -34,4 +34,4 @@ If a target passes a request, the request is still considered _unmatched_ or _un
|
|
34
34
|
|
35
35
|
Redirections
|
36
36
|
------------
|
37
|
-
A common requirement of many applications is to redirect requests to another URL based on some kind of condition. Scorched offers the very simple `redirect` method which takes one required argument - the absolute or relative URL to redirect to - and an optional response status, which defaults to either 303 or 302 depending on the HTTP protocol version used for the request.
|
37
|
+
A common requirement of many applications is to redirect requests to another URL based on some kind of condition. Scorched offers the very simple `redirect` method which takes one required argument - the absolute or relative URL to redirect to - and an optional response status, which defaults to either a 303 or 302 response status depending on the HTTP protocol version used for the request.
|
data/examples/file_upload.ru
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path('../../lib/scorched.rb', __FILE__)
|
2
|
+
require 'mimemagic'
|
2
3
|
|
3
4
|
class MediaTypesExample < Scorched::Controller
|
4
5
|
|
5
6
|
get '/' do
|
6
|
-
response['Content-Type'] = 'text/html'
|
7
7
|
<<-HTML
|
8
8
|
<form method="POST" action="#{absolute(request.matched_path)}" enctype="multipart/form-data">
|
9
9
|
<input type="file" name="example_file" />
|
@@ -14,28 +14,25 @@ class MediaTypesExample < Scorched::Controller
|
|
14
14
|
|
15
15
|
post '/' do
|
16
16
|
example_file = request[:example_file]
|
17
|
+
mime = MimeMagic.by_magic(example_file[:tempfile])
|
17
18
|
<<-HTML
|
18
19
|
We know the following about the received file.
|
19
20
|
<ul>
|
20
21
|
<li><strong>Name:</strong> #{example_file[:filename]}</li>
|
21
22
|
<li><strong>Supposed Type:</strong> #{example_file[:type]}</li>
|
22
|
-
<li><strong>Actual Type:</strong>
|
23
|
+
<li><strong>Actual Type:</strong> #{mime ? mime.type : "Unknown"}</li>
|
23
24
|
<li><strong>Size:</strong> #{format_byte_size example_file[:tempfile].size}</li>
|
24
25
|
</ul>
|
25
26
|
HTML
|
26
27
|
end
|
27
28
|
|
28
|
-
after do
|
29
|
-
response['Content-Type'] = 'text/html; charset=utf-8' unless response['Content-Type']
|
30
|
-
end
|
31
|
-
|
32
29
|
# My self-proclaimed awesome byte size formatter: https://gist.github.com/Wardrop/4952405
|
33
30
|
def format_byte_size(bytes, opts = {})
|
34
31
|
opts = {binary: true, precision: 2, as_bits: false}.merge(opts)
|
35
32
|
suffixes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB','EB', 'ZB', 'YB']
|
36
33
|
opts[:as_bits] && suffixes[0] = 'bits' && suffixes[1..-1].each { |v| v.downcase! } && bytes *= 8
|
37
34
|
opts[:binary] ? base = 1024 : (base = 1000) && suffixes[1..-1].each { |v| v.insert(1,'i') }
|
38
|
-
exp = Math.log(bytes, base).floor
|
35
|
+
exp = bytes.zero? ? bytes : Math.log(bytes, base).floor
|
39
36
|
"#{(bytes.to_f / (base ** exp)).round(opts[:precision])} #{suffixes[exp]}"
|
40
37
|
end
|
41
38
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path('../../lib/scorched.rb', __FILE__)
|
2
|
+
require 'sequel'
|
3
|
+
|
4
|
+
Sequel::Model.db = Sequel.sqlite("development.db")
|
5
|
+
|
6
|
+
class Tasks < Sequel::Model
|
7
|
+
db.create_table? :tasks do
|
8
|
+
primary_key :id
|
9
|
+
String :name
|
10
|
+
DateTime :completed_at
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class App < Scorched::Controller
|
15
|
+
controller '/tasks' do
|
16
|
+
get '/' do
|
17
|
+
@tasks = Tasks.all
|
18
|
+
render :index
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/:id' do
|
22
|
+
render :task, locals: {task: task}
|
23
|
+
end
|
24
|
+
|
25
|
+
post '/' do
|
26
|
+
id = Tasks.insert(:name => request.POST['name'])
|
27
|
+
redirect "/tasks/#{id}"
|
28
|
+
end
|
29
|
+
|
30
|
+
put '/:id' do
|
31
|
+
task.update(completed_at: (request.POST['completed'] ? Time.now : nil), name: request.POST['name'])
|
32
|
+
redirect "/tasks/#{captures[:id]}"
|
33
|
+
end
|
34
|
+
|
35
|
+
delete '/:id' do
|
36
|
+
task.delete
|
37
|
+
redirect "/tasks"
|
38
|
+
end
|
39
|
+
|
40
|
+
def task(id = captures[:id])
|
41
|
+
Tasks[id] || halt(404)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
run App
|
@@ -6,6 +6,7 @@ end
|
|
6
6
|
class Base < App
|
7
7
|
def self.inherited(klass)
|
8
8
|
klass.get('/') { invoke_action :index }
|
9
|
+
klass.get('/new') { invoke_action :new }
|
9
10
|
klass.post('/') { invoke_action :create }
|
10
11
|
klass.get('/:id') { invoke_action :show }
|
11
12
|
klass.get('/:id/edit') { invoke_action :edit }
|
data/examples/simple.ru
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'scorched'
|
2
2
|
|
3
3
|
class App < Scorched::Controller
|
4
|
-
get '
|
5
|
-
|
4
|
+
get '/:name' do
|
5
|
+
@message = greeting(captures[:name])
|
6
|
+
render :hello
|
7
|
+
end
|
8
|
+
|
9
|
+
def greeting(name)
|
10
|
+
"Howdy #{name}"
|
6
11
|
end
|
7
12
|
end
|
8
13
|
|
9
|
-
run App
|
14
|
+
run App
|
data/lib/scorched/controller.rb
CHANGED
@@ -370,8 +370,9 @@ module Scorched
|
|
370
370
|
invert ? !retval : !!retval
|
371
371
|
end
|
372
372
|
|
373
|
+
# Redirects to the specified path or URL. An optional HTTP status is also accepted.
|
373
374
|
def redirect(url, status = (env['HTTP_VERSION'] == 'HTTP/1.1') ? 303 : 302)
|
374
|
-
response['Location'] = url
|
375
|
+
response['Location'] = absolute(url)
|
375
376
|
halt(status)
|
376
377
|
end
|
377
378
|
|
@@ -524,8 +525,10 @@ module Scorched
|
|
524
525
|
return_path[0] == '/' ? return_path : return_path.insert(0, '/')
|
525
526
|
end
|
526
527
|
|
527
|
-
|
528
|
-
|
528
|
+
# We always want this filter to run at the end-point controller, hence we include the conditions within the body of
|
529
|
+
# the filter.
|
530
|
+
after do
|
531
|
+
if response.empty? && !check_for_failed_condition(config: {show_http_error_pages: true}, status: 400..599)
|
529
532
|
response.body = <<-HTML
|
530
533
|
<!DOCTYPE html>
|
531
534
|
<html>
|
data/lib/scorched/version.rb
CHANGED
data/scorched.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new 'scorched', Scorched::VERSION do |s|
|
|
10
10
|
s.license = 'MIT'
|
11
11
|
s.files = Dir.glob(`git ls-files`.split("\n") - %w[.gitignore])
|
12
12
|
s.test_files = Dir.glob('spec/**/*_spec.rb')
|
13
|
-
s.
|
13
|
+
s.has_rdoc = 'yard'
|
14
14
|
|
15
15
|
s.required_ruby_version = '>= 2.0.0'
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorched
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.22'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Wardrop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -101,6 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- .yardopts
|
104
105
|
- CHANGES.md
|
105
106
|
- Gemfile
|
106
107
|
- LICENSE
|
@@ -122,6 +123,7 @@ files:
|
|
122
123
|
- docs/03_further_reading/live_console.md
|
123
124
|
- docs/03_further_reading/running_unit_tests.md
|
124
125
|
- examples/file_upload.ru
|
126
|
+
- examples/less_simple.ru
|
125
127
|
- examples/media_types.ru
|
126
128
|
- examples/rails_style_routing.ru
|
127
129
|
- examples/simple.ru
|
@@ -153,12 +155,7 @@ licenses:
|
|
153
155
|
- MIT
|
154
156
|
metadata: {}
|
155
157
|
post_install_message:
|
156
|
-
rdoc_options:
|
157
|
-
- --line-numbers
|
158
|
-
- --inline-source
|
159
|
-
- --title
|
160
|
-
- Scorched
|
161
|
-
- --encoding=UTF-8
|
158
|
+
rdoc_options: []
|
162
159
|
require_paths:
|
163
160
|
- lib
|
164
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|