woah 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/woah/base.rb +28 -22
- data/lib/woah/route.rb +1 -0
- data/lib/woah/version.rb +1 -1
- data/test/test_helper.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb45f60031e5467ff757e5095e822a7bef583a6225840bfc917b2795afd40bc3
|
4
|
+
data.tar.gz: 63afa8fe95815849bdd0f2362336cc21d50ebb902e3b8c424d6891c586f3a3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cb1e9b4287a3ee58d25c1db92138d7eb1572e6665bcefcfc4679908639d8af4a5d0d3b7a1e01b906fcbc2d3ae8584fc1530737e66d8e098f4472d4c85acb45
|
7
|
+
data.tar.gz: 39c4fa1fa939c57a4ccc44eeb27e5c46689995a4394691d7f51c0300aade6d0772ae881bc11ec25c55ce0251ccaf2d86259bcc2ba90770897b2ea536c43fdd5a
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Woah!
|
2
2
|
[![Build Status](https://travis-ci.org/knarka/woah.svg?branch=master)](https://travis-ci.org/knarka/woah)
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/github/knarka/woah/badge.svg?branch=master&service=github)](https://coveralls.io/github/knarka/woah?branch=master)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/knarka/woah/badges/gpa.svg)](https://codeclimate.com/github/knarka/woah)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/woah.svg)](https://badge.fury.io/rb/woah)
|
5
6
|
|
6
7
|
Woah! is an unobtrusive, (extremely) minimal web framework built on Rack.
|
@@ -89,7 +90,7 @@ class MyApp < Woah::Base
|
|
89
90
|
end
|
90
91
|
```
|
91
92
|
|
92
|
-
Now, visiting `/greet/Socrates` will greet you with your own name. Wonderful. By the way, you may have noticed the regex here is delimited by `%r{}`, instead of the more common `//`. This is because of how common slashes are in routes, so it's recommended to use this syntax. You can use slashes to delimit your regex though, if you like. I won't judge you.
|
93
|
+
Now, visiting `/greet/Socrates` will greet you with your own name (assuming your name is Socrates). Wonderful. By the way, you may have noticed the regex here is delimited by `%r{}`, instead of the more common `//`. This is because of how common slashes are in routes, so it's recommended to use this syntax. You can use slashes to delimit your regex though, if you like. I won't judge you.
|
93
94
|
|
94
95
|
Redirects are possible as well:
|
95
96
|
|
data/lib/woah/base.rb
CHANGED
@@ -5,13 +5,12 @@ module Woah
|
|
5
5
|
class Base
|
6
6
|
@@before = nil
|
7
7
|
@@after = nil
|
8
|
-
@@match = nil
|
9
|
-
@@request = nil
|
10
8
|
@@routes = []
|
11
9
|
|
12
10
|
def initialize
|
13
11
|
@@override = {}
|
14
12
|
@@match = nil
|
13
|
+
@@request = nil
|
15
14
|
@@response = nil
|
16
15
|
end
|
17
16
|
|
@@ -47,7 +46,7 @@ module Woah
|
|
47
46
|
|
48
47
|
# Resolves and executes a round
|
49
48
|
# @param path [String, Regexp] the path to respond to
|
50
|
-
# @param method [String] the
|
49
|
+
# @param method [String] the HTTP method to use
|
51
50
|
# @return [Hash] the route's response
|
52
51
|
def resolve_route(path, method)
|
53
52
|
route = @@routes.select { |r| r.matches?(method, path) }[0]
|
@@ -72,15 +71,15 @@ module Woah
|
|
72
71
|
end
|
73
72
|
|
74
73
|
# Get this show on the road.
|
75
|
-
# @host [String] the host to use
|
76
|
-
# @port [Integer] the port to use
|
74
|
+
# @param host [String] the host to use
|
75
|
+
# @param port [Integer] the port to use
|
77
76
|
def run!(host = '0.0.0.0', port = 4422)
|
78
77
|
Rack::Handler.pick(%w[thin puma]).run new, Host: host, Port: port
|
79
78
|
end
|
80
79
|
|
81
80
|
# Register new routes. The optional method argument can be used to specify a method
|
82
81
|
# @param path [String, Regexp] the path to respond to
|
83
|
-
# @param method [String] the
|
82
|
+
# @param method [String] the HTTP method to use
|
84
83
|
# @raise [ArgumentError] if `method` is not a valid HTTP method
|
85
84
|
def on(path, method = 'GET', &action)
|
86
85
|
unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
|
@@ -131,25 +130,12 @@ module Woah
|
|
131
130
|
# @param key [String] the name of the cookie
|
132
131
|
# @param value [nil, :delete, String]
|
133
132
|
def cookie(key, value = nil)
|
134
|
-
# Read cookie
|
135
133
|
if value.nil?
|
136
|
-
|
137
|
-
s = c.split('=')
|
138
|
-
return s[1] if s[0] == key
|
139
|
-
end
|
140
|
-
nil # if not found
|
141
|
-
|
142
|
-
# Delete cookie
|
134
|
+
read_cookie key
|
143
135
|
elsif value == :delete
|
144
|
-
|
145
|
-
Rack::Utils.delete_cookie_header! @@override[:headers], key
|
146
|
-
|
147
|
-
# Set cookie
|
136
|
+
del_cookie key
|
148
137
|
elsif value.is_a? String
|
149
|
-
|
150
|
-
Rack::Utils.set_cookie_header! @@override[:headers], key, value
|
151
|
-
|
152
|
-
# Invalid argument
|
138
|
+
set_cookie key, value
|
153
139
|
else
|
154
140
|
raise ArgumentError, 'Value should be either nil, :delete, or a string'
|
155
141
|
end
|
@@ -164,6 +150,26 @@ module Woah
|
|
164
150
|
def request
|
165
151
|
@@request
|
166
152
|
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def read_cookie(key)
|
157
|
+
@@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
|
158
|
+
s = c.split('=')
|
159
|
+
return s[1] if s[0] == key
|
160
|
+
end
|
161
|
+
nil # if not found
|
162
|
+
end
|
163
|
+
|
164
|
+
def del_cookie(key)
|
165
|
+
@@override[:headers] ||= {}
|
166
|
+
Rack::Utils.delete_cookie_header! @@override[:headers], key
|
167
|
+
end
|
168
|
+
|
169
|
+
def set_cookie(key, value)
|
170
|
+
@@override[:headers] ||= {}
|
171
|
+
Rack::Utils.set_cookie_header! @@override[:headers], key, value
|
172
|
+
end
|
167
173
|
end
|
168
174
|
end
|
169
175
|
end
|
data/lib/woah/route.rb
CHANGED
data/lib/woah/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knarka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -16,16 +16,16 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.
|
19
|
+
version: 2.0.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.
|
27
|
-
description: "Woah! is a minimal web framework built on Rack
|
28
|
-
|
26
|
+
version: 2.0.6
|
27
|
+
description: "Woah! is a minimal web framework built on Rack designed to let you just
|
28
|
+
do your\n\tthing."
|
29
29
|
email: knarka@airmail.cc
|
30
30
|
executables: []
|
31
31
|
extensions: []
|