ruboty-router 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: 568959b2fc8f93452bfbe41416c1a38ed06dea0e
4
- data.tar.gz: f33215897514a21b4e27a6a60d2eb4054957ebae
3
+ metadata.gz: 446b30b73f295d383860ac1ce959b70830aa8379
4
+ data.tar.gz: 4a0788aeb29772ff030e88b56ae4460d22dad8e7
5
5
  SHA512:
6
- metadata.gz: 78a71269d6f4554ff72233d7c84adafaea3dc6fbab9a6195767bb619294611a0391c3c42fcf05e81a2c167d1cb62ab2717059e44f4243638b311536f51b1cce8
7
- data.tar.gz: 750c364db78c2a3f6b9474ccff6341d609bdb22d2a44e2b5f0f358e58f67cae720e5e641ec3bed4e04dc95300dbf679e1904c9fa3491a48b47cbfb8c343a70c8
6
+ metadata.gz: a880a5883b8fd1ad0712367420ed28b41a414d33230b9284c48865d000c4d74df6ad88aa68f747351389da2b1f83e47ef74d95006560f024bfdb855d2045a859
7
+ data.tar.gz: c7bf0302d76944fe01e6a9a6d63095679b16b99ca3f05e7558a7f18b7db69614bf3c2d95a7145675ba8383e958e9d54ac08ba36e734d61f44875cb351beed091
data/.gitignore CHANGED
@@ -31,6 +31,7 @@ config/initializers/secret_token.rb
31
31
  # these should all be checked in to normalize the environment:
32
32
  # Gemfile.lock, .ruby-version, .ruby-gemset
33
33
  Gemfile.lock
34
+ pkg/
34
35
 
35
36
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
37
  .rvmrc
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.1
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-url.svg?branch=master)](https://travis-ci.org/zeero/ruboty-url)
2
- [![Gem Version](https://badge.fury.io/rb/ruboty-url.svg)](https://badge.fury.io/rb/ruboty-url)
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::Ruboty::Router
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
- Sample definition is below:
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>)` add routing
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
+
@@ -9,6 +9,10 @@ module Ruboty
9
9
  end
10
10
 
11
11
  def call(router, _options = {})
12
+ unless path.start_with? '/'
13
+ puts I18n.t('warnings.invalid_route', path: path)
14
+ return {}
15
+ end
12
16
  proc = lambda do |env|
13
17
  req = Rack::Request.new(env)
14
18
  res = Rack::Response.new
@@ -0,0 +1,4 @@
1
+ en:
2
+ warnings:
3
+ invalid_route: "Ruboty::Router: Failed to define route for '%{path}'. Path must start with '/'."
4
+
@@ -11,7 +11,7 @@ module Ruboty
11
11
  Thread.new do
12
12
  Rack::Server.start(
13
13
  app: app(robot),
14
- Port: Ruboty::Router::RUBOTY_ROUTER_PORT,
14
+ Port: Ruboty::Router::RUBOTY_ROUTER_PORT
15
15
  )
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Router
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -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.add_dependency 'activesupport'
21
- spec.add_dependency 'mem'
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.1.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-15 00:00:00.000000000 Z
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