web_router 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/README.md +26 -1
- data/lib/web_router/router.rb +4 -7
- data/lib/web_router/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf2d63560060a2e0fea9c1528cc4510d51ba4b8
|
4
|
+
data.tar.gz: a720b2011e9abe331e9e0c95aaec7e5c46b61b45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e18908986771377366b58799852c9a49b7dc9fe4c1cf2ece0b7254533125a2efed29dcd271c5ae463652b131da20941b6b0545405b5428c0114f7a5bc34d52
|
7
|
+
data.tar.gz: 0077269c48ddd3758f5c0fed3ba254fd5b2b2c907f8f501e1c1d056d1c6f3ed9f1112f3277cb15542d20bd96ac7aac2bf591d661df15b5bb6bd10300206f8ab7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -25,8 +25,33 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
28
|
+
1. Write controllers with methods. WebRouter controllers responds to json, text
|
29
29
|
|
30
|
+
```ruby
|
31
|
+
class TestsController < WebRouter::Controller
|
32
|
+
def show
|
33
|
+
response(:json, params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test
|
37
|
+
response(:text, "Required method #{request.request_method}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
2. Create new application and configure it with block of routes
|
43
|
+
Available HTTP methods: get, post, put, delete
|
44
|
+
You can configure routs using controller`s methods or Rack Applications
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
WebRouter::Router.new.configure do
|
48
|
+
get '/test', ->(env) { [200, {}, ['get test']] }
|
49
|
+
post '/test', ->(env) { [200, {}, ['post test']] }
|
50
|
+
get '/comments/:name/:other_one', 'tests#show'
|
51
|
+
get '/testing', 'tests#test'
|
52
|
+
end
|
53
|
+
|
54
|
+
```
|
30
55
|
## Development
|
31
56
|
|
32
57
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/web_router/router.rb
CHANGED
@@ -15,13 +15,10 @@ private
|
|
15
15
|
@routes = []
|
16
16
|
end
|
17
17
|
|
18
|
-
def get(path, rack_app)
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def post(path, rack_app)
|
23
|
-
match('POST', path, rack_app)
|
24
|
-
end
|
18
|
+
def get(path, rack_app) match('GET', path, rack_app) end
|
19
|
+
def post(path, rack_app) match('POST', path, rack_app) end
|
20
|
+
def put(path, rack_app) match('PUT', path, rack_app) end
|
21
|
+
def delete(path, rack_app) match('DELETE', path, rack_app) end
|
25
22
|
|
26
23
|
def match(http_method, path, rack_app)
|
27
24
|
rack_app = get_controller_action(rack_app) if rack_app.is_a? String
|
data/lib/web_router/version.rb
CHANGED