woah 0.0.1 → 0.0.2
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/README.md +54 -1
- data/lib/woah/base.rb +4 -10
- data/lib/woah/version.rb +1 -1
- data/test/basic_verbs_test.rb +9 -0
- data/test/on_method_test.rb +43 -0
- data/test/test_helper.rb +3 -0
- data/test/testapp.rb +6 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2719ba8762336269cf1ec3b13117229a772bb954bbcc9134360df30e7b62665f
|
4
|
+
data.tar.gz: 65b23b7632a6db0add321ed2a86c2c0ea310733d5f1a35ea4394155c57a8ea3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e12c37e93d46e8add7645b7b5178440f044205cf9e333c86dcfd75f570100cef96df1fe0d1076e08b330d28ffd54e5a1a40653d78a36a4efdb92d3e0cee8a92
|
7
|
+
data.tar.gz: 57b835da89e4967122b33a16b60a446fc6c1d9884e662a508d97d513f56959a87e3787552d891832ce53611ad940b3529e79a0457a1e4ac16258758413e78159
|
data/README.md
CHANGED
@@ -1,5 +1,58 @@
|
|
1
1
|
# Woah!
|
2
|
-
|
2
|
+
[](https://travis-ci.org/knarka/woah)
|
3
|
+
[](https://badge.fury.io/rb/woah)
|
4
|
+
|
5
|
+
Woah! is a minimal web framework built on Rack. It's primary design goal is to be unobtrusive, and to just let you do your thing, dude.
|
3
6
|
|
4
7
|
## Installation
|
5
8
|
`gem install woah`
|
9
|
+
|
10
|
+
## What now???
|
11
|
+
Easy. You're gonna want to extend Woah::Base, which will be your app's, er, base.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'woah'
|
15
|
+
|
16
|
+
class MyApp < Woah::Base
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
Woah, that's easy. Now let's add a route.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'woah'
|
24
|
+
|
25
|
+
class MyApp < Woah::Base
|
26
|
+
on '/hello' do
|
27
|
+
"hey, what's up"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
When someone stumbles upon `/hello` now, they'll be greeted properly. Nice. We call these blocks of code **routes**. There's more types of blocks than just routes though. Check this out:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'woah'
|
36
|
+
|
37
|
+
class MyApp < Woah::Base
|
38
|
+
before do
|
39
|
+
@@num ||= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
on '/' do
|
43
|
+
"this is the root of this app, and page hit nr. #{@@num}"
|
44
|
+
end
|
45
|
+
|
46
|
+
on '/hello' do
|
47
|
+
"hey, what's up. this is page hit nr. #{@@num}"
|
48
|
+
end
|
49
|
+
|
50
|
+
after do
|
51
|
+
@@num += 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
There's two new blocks here: `before` and `after`. They do things before and after the relevant route gets executed (duh!). This example will increment a counter everytime a page is hit, regardless of what page it is.
|
57
|
+
|
58
|
+
More to come.
|
data/lib/woah/base.rb
CHANGED
@@ -9,7 +9,7 @@ module Woah
|
|
9
9
|
|
10
10
|
# answer the phone
|
11
11
|
def self.call(env)
|
12
|
-
route = @@routes[env['REQUEST_URI']]
|
12
|
+
route = @@routes[[env['REQUEST_URI'], env['REQUEST_METHOD']]]
|
13
13
|
@@override = {}
|
14
14
|
|
15
15
|
@@before&.call
|
@@ -26,8 +26,9 @@ module Woah
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# register new routes
|
29
|
-
def self.on(path, &action)
|
30
|
-
|
29
|
+
def self.on(path, method = 'GET', &action)
|
30
|
+
raise 'unknown method' unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
|
31
|
+
@@routes[[path, method]] = Route.new(path, method, &action)
|
31
32
|
end
|
32
33
|
|
33
34
|
# things to do before handling the routes
|
@@ -52,12 +53,5 @@ module Woah
|
|
52
53
|
def self.run!(port = 4422)
|
53
54
|
Rack::Handler.pick(%w[thin webrick]).run new, Port: port
|
54
55
|
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
# log to stdout
|
59
|
-
def say(message)
|
60
|
-
puts 'Woah! ' + message.capitalize
|
61
|
-
end
|
62
56
|
end
|
63
57
|
end
|
data/lib/woah/version.rb
CHANGED
data/test/basic_verbs_test.rb
CHANGED
@@ -14,6 +14,15 @@ class BasicVerbsTest < MiniTest::Test
|
|
14
14
|
assert_equal 'hi there!', response[2]
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_post
|
18
|
+
@env['REQUEST_URI'] = '/'
|
19
|
+
@env['REQUEST_METHOD'] = 'POST'
|
20
|
+
response = TestApp.call @env
|
21
|
+
|
22
|
+
assert_equal 200, response[0]
|
23
|
+
assert_equal 'got post!', response[2]
|
24
|
+
end
|
25
|
+
|
17
26
|
def test_get_404
|
18
27
|
@env['REQUEST_URI'] = '/does/not/exist'
|
19
28
|
@env['REQUEST_METHOD'] = 'GET'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class OnMethodTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_throw_404
|
9
|
+
TestApp.on '/404' do
|
10
|
+
TestApp.set :status, 404
|
11
|
+
"it's a secret to everybody"
|
12
|
+
end
|
13
|
+
|
14
|
+
@env['REQUEST_URI'] = '/404'
|
15
|
+
@env['REQUEST_METHOD'] = 'GET'
|
16
|
+
response = TestApp.call @env
|
17
|
+
|
18
|
+
assert_equal 404, response[0]
|
19
|
+
assert_equal "it's a secret to everybody", response[2]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_illegal_method
|
23
|
+
assert_raises RuntimeError do
|
24
|
+
TestApp.on '/', 'BUBBLES' do
|
25
|
+
'oOooo oO oO'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@env['REQUEST_URI'] = '/'
|
30
|
+
@env['REQUEST_METHOD'] = 'BUBBLES'
|
31
|
+
response = TestApp.call @env
|
32
|
+
|
33
|
+
assert_equal 404, response[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_illegal_set
|
37
|
+
TestApp.on '/nose' do
|
38
|
+
assert_raises RuntimeError do
|
39
|
+
TestApp.set :nose, true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/testapp.rb
CHANGED
@@ -3,12 +3,16 @@
|
|
3
3
|
require_relative '../lib/woah'
|
4
4
|
|
5
5
|
class TestApp < Woah::Base
|
6
|
+
before do
|
7
|
+
@@time = 'chunky'
|
8
|
+
end
|
9
|
+
|
6
10
|
on '/' do
|
7
11
|
'hi there!'
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
on '/', 'POST' do
|
15
|
+
'got post!'
|
12
16
|
end
|
13
17
|
|
14
18
|
on '/before_after' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knarka
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/woah/version.rb
|
40
40
|
- test/basic_verbs_test.rb
|
41
41
|
- test/before_after_test.rb
|
42
|
+
- test/on_method_test.rb
|
42
43
|
- test/test_helper.rb
|
43
44
|
- test/testapp.rb
|
44
45
|
homepage: https://github.com/knarka/woah
|