ruboty-router 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -1
- data/README.md +11 -6
- data/lib/ruboty/router.rb +3 -0
- data/lib/ruboty/router/action.rb +4 -0
- data/lib/ruboty/router/locale/en.yml +4 -0
- data/lib/ruboty/router/server.rb +1 -1
- data/lib/ruboty/router/version.rb +1 -1
- data/ruboty-router.gemspec +3 -2
- data/test/ruboty/routers/sample_test.rb +14 -0
- data/test/test_helper.rb +6 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 446b30b73f295d383860ac1ce959b70830aa8379
|
4
|
+
data.tar.gz: 4a0788aeb29772ff030e88b56ae4460d22dad8e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a880a5883b8fd1ad0712367420ed28b41a414d33230b9284c48865d000c4d74df6ad88aa68f747351389da2b1f83e47ef74d95006560f024bfdb855d2045a859
|
7
|
+
data.tar.gz: c7bf0302d76944fe01e6a9a6d63095679b16b99ca3f05e7558a7f18b7db69614bf3c2d95a7145675ba8383e958e9d54ac08ba36e734d61f44875cb351beed091
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
|
4
|
+
- 2.3.1
|
5
|
+
- 2.5.0
|
5
6
|
before_install: gem install bundler -v 1.16.1
|
7
|
+
notifications:
|
8
|
+
slack:
|
9
|
+
secure: pUf7sKs4KrLYxmblc28Gs/lSCZGqhPpeMFQFfI0QpUmtEAzavchbe0hkdldp/pMNWb1XmembPbwhkasyGpEk9l1/rkheL0Uyg+leEVLX0LgH61sD7Zt00MaGvdMz7GJQFVLHObu7zSR6sy8Jb0NpjVnPc4jDB8wrWEnu2hHAwpba9SELOYKmWQ/qUWoDCFRhsVOZHDOWJUvWj0lVpWcbJvmk2yWUpV6pifWY8KBBT+r3MTvx8yX8jr70j5hw5eP2xW+ZIoDWDtX9ZZI17zOhzEr0vUUMgSzcY4JxeBKeK1MbDmYQ5qbr4DZ3AN4NDAMDH53BwbGRCQt3yrNaLvonzPVOfvtJcqfs79wCqnhW3rfBbvRCQi+ldtQBkM4JpyeGhlV7FY+NjLIjycu5OyyzmXXhhifV7nDX+n4v/z/z5ukygZijHTMQNiIOjc6pXcUjpJgILJthK3PN8jnkBiyYLqV/6qMnl0Srf9fcYVW0Hpm7ehlaeTHYXsygma7CG4DAJEHp8HJozTzXLB/8RcHhGgQR/pa7K4XUaUsTF5h2aYcFNZB9+fQFX9KFI2ShT07ADoY8dMZ+T3qrgrU5NlIICtMDhIrcDKkepwWfjjM/4Tlj4QafML85jsWTk5YH5/cR+CMPQ1RGrX2n23SFa6bRR6AThZE+Rc1N6kalLZiRt1U=
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/zeero/ruboty-
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/ruboty-
|
1
|
+
[![Build Status](https://travis-ci.org/zeero/ruboty-router.svg?branch=master)](https://travis-ci.org/zeero/ruboty-router)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/ruboty-router.svg)](https://badge.fury.io/rb/ruboty-router)
|
3
3
|
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE.txt)
|
4
4
|
|
5
|
-
# Ruboty::
|
5
|
+
# Ruboty::Router
|
6
6
|
|
7
7
|
A Ruboty Handler + Actions to enable routing function to Ruboty.
|
8
8
|
|
@@ -22,7 +22,10 @@ And then execute:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
WEBrick will start with port 9292 by default, when starting Ruboty.
|
26
|
+
|
27
|
+
You can define routings by Ruboty::Routers class.
|
28
|
+
Sample is below:
|
26
29
|
|
27
30
|
```ruby
|
28
31
|
module Ruboty
|
@@ -45,7 +48,9 @@ module Ruboty
|
|
45
48
|
end
|
46
49
|
```
|
47
50
|
|
48
|
-
* `route(<path>, name: <method_name>, description: <description>)`
|
51
|
+
* `route(<path>, name: <method_name>, description: <description>)`
|
52
|
+
* add routing
|
53
|
+
* *<path> must start with '/'*
|
49
54
|
* `def sample(req, res)`
|
50
55
|
* Routing method definition
|
51
56
|
* Method receive [Rack::Request](http://www.rubydoc.info/gems/rack/Rack/Request) and [Rack::Response](http://www.rubydoc.info/gems/rack/Rack/Response)
|
@@ -54,7 +59,7 @@ end
|
|
54
59
|
|
55
60
|
|Name|Description|
|
56
61
|
|:--|:--|
|
57
|
-
|RUBOTY_ROUTER_PORT|HTTP listen port|
|
62
|
+
|RUBOTY_ROUTER_PORT|HTTP listen port (default: 9292)|
|
58
63
|
|
59
64
|
## Contributing
|
60
65
|
|
data/lib/ruboty/router.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
+
require 'i18n'
|
3
4
|
require 'mem'
|
4
5
|
require 'rack'
|
5
6
|
require 'webrick'
|
@@ -23,3 +24,5 @@ require_relative 'robot.patch'
|
|
23
24
|
Dir[File.expand_path('router', __dir__) << '/**/*.rb'].each { |file| require file }
|
24
25
|
Dir[File.expand_path('routers', __dir__) << '/**/*.rb'].each { |file| require file }
|
25
26
|
|
27
|
+
I18n.load_path << Dir[File.expand_path('router/locale/*.yml', __dir__)]
|
28
|
+
|
data/lib/ruboty/router/action.rb
CHANGED
data/lib/ruboty/router/server.rb
CHANGED
data/ruboty-router.gemspec
CHANGED
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.
|
21
|
-
spec.
|
20
|
+
spec.add_runtime_dependency 'activesupport'
|
21
|
+
spec.add_runtime_dependency 'i18n'
|
22
|
+
spec.add_runtime_dependency 'mem'
|
22
23
|
spec.add_runtime_dependency 'rack'
|
23
24
|
spec.add_runtime_dependency 'ruboty'
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
@@ -6,6 +6,11 @@ describe Ruboty::Routers::Sample do
|
|
6
6
|
let(:robot) { Ruboty::Robot.new }
|
7
7
|
|
8
8
|
before do
|
9
|
+
$stdout = StringIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
$stdout = STDOUT
|
9
14
|
end
|
10
15
|
|
11
16
|
def app
|
@@ -33,5 +38,14 @@ describe Ruboty::Routers::Sample do
|
|
33
38
|
last_response.body.must_equal 'Child!'
|
34
39
|
end
|
35
40
|
end
|
41
|
+
|
42
|
+
describe 'failed' do
|
43
|
+
it 'should display warning message' do
|
44
|
+
get 'failed'
|
45
|
+
last_response.body.wont_equal 'Failed!'
|
46
|
+
output = $stdout.string
|
47
|
+
output.must_equal I18n.t('warnings.invalid_route', path: 'failed') + "\n"
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
data/test/test_helper.rb
CHANGED
@@ -14,6 +14,7 @@ module Ruboty
|
|
14
14
|
class Sample < Base
|
15
15
|
route('/sample', name: 'sample', description: 'sample router for unit test.')
|
16
16
|
route('/sample/child', name: 'child', description: 'sample router for unit test.')
|
17
|
+
route('failed', name: 'failed', description: 'sample router for unit test.')
|
17
18
|
|
18
19
|
def sample(_req, res)
|
19
20
|
res.write 'Sample!'
|
@@ -24,6 +25,11 @@ module Ruboty
|
|
24
25
|
res.write 'Child!'
|
25
26
|
robot.say(body: 'something to say for child')
|
26
27
|
end
|
28
|
+
|
29
|
+
def failed(_req, res)
|
30
|
+
res.write 'Failed!'
|
31
|
+
robot.say(body: 'something to say for failed')
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zeero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: mem
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,6 +240,7 @@ files:
|
|
226
240
|
- lib/ruboty/robot.patch.rb
|
227
241
|
- lib/ruboty/router.rb
|
228
242
|
- lib/ruboty/router/action.rb
|
243
|
+
- lib/ruboty/router/locale/en.yml
|
229
244
|
- lib/ruboty/router/server.rb
|
230
245
|
- lib/ruboty/router/version.rb
|
231
246
|
- lib/ruboty/routers/base.rb
|