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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82df5f493573f4a67b6e3d3db58284a3e6b0133d00345f13621d4a926664322a
4
- data.tar.gz: 8db367f1aab0d3771a9eb3d5c90ce2162b976ab0f3507388161668350f3542a7
3
+ metadata.gz: 2719ba8762336269cf1ec3b13117229a772bb954bbcc9134360df30e7b62665f
4
+ data.tar.gz: 65b23b7632a6db0add321ed2a86c2c0ea310733d5f1a35ea4394155c57a8ea3a
5
5
  SHA512:
6
- metadata.gz: 887ca9930919b7bc102baa92c82d1c9385ebb4107c16f9f9cdea540603ec101f7cba07583bf7b055f24a17628c178d17fab869a29af81686daf8a0cce0ef186b
7
- data.tar.gz: a6bd22cfe51db5d981a4cf26ef6cbba077df61e0cc1b2e35793d416ed807af7ddc44427349661b435a9b24f6e5c0ad816725b64084a0ec6d3e3b4f8e0a61d77b
6
+ metadata.gz: 9e12c37e93d46e8add7645b7b5178440f044205cf9e333c86dcfd75f570100cef96df1fe0d1076e08b330d28ffd54e5a1a40653d78a36a4efdb92d3e0cee8a92
7
+ data.tar.gz: 57b835da89e4967122b33a16b60a446fc6c1d9884e662a508d97d513f56959a87e3787552d891832ce53611ad940b3529e79a0457a1e4ac16258758413e78159
data/README.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # Woah!
2
- Woah! is a simple (yet another) web framework in Ruby.
2
+ [![Build Status](https://travis-ci.org/knarka/woah.svg?branch=master)](https://travis-ci.org/knarka/woah)
3
+ [![Gem Version](https://badge.fury.io/rb/woah.svg)](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
- @@routes[path] = Route.new(path, 'GET', &action)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Woah
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -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
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'test/'
6
+ end
4
7
  SimpleCov.start
5
8
 
6
9
  ENV['RACK_ENV'] = 'test'
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
- before do
11
- @@time = 'chunky'
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.1
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