Lotus => Hanami
This commit is contained in:
parent
467abe2522
commit
f945b4f31c
20
.travis.yml
20
.travis.yml
|
@ -3,24 +3,9 @@ sudo: false
|
|||
cache: bundler
|
||||
script: 'bundle exec rake test:coverage --trace'
|
||||
rvm:
|
||||
- 2.0.0
|
||||
- 2.1.0
|
||||
- 2.1.1
|
||||
- 2.1.2
|
||||
- 2.1.3
|
||||
- 2.1.4
|
||||
- 2.1.5
|
||||
- 2.1.6
|
||||
- 2.1.7
|
||||
- 2.1.8
|
||||
- 2.2.0
|
||||
- 2.2.1
|
||||
- 2.2.2
|
||||
- 2.2.3
|
||||
- 2.2.4
|
||||
- 2.3.0
|
||||
- 2.2
|
||||
- 2.3
|
||||
- jruby-9000
|
||||
- rbx-2
|
||||
- ruby-head
|
||||
- jruby-head
|
||||
|
||||
|
@ -28,4 +13,3 @@ matrix:
|
|||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
- rvm: jruby-head
|
||||
- rvm: rbx-2
|
||||
|
|
42
CHANGELOG.md
42
CHANGELOG.md
|
@ -1,4 +1,4 @@
|
|||
# Lotus::Router
|
||||
# Hanami::Router
|
||||
Rack compatible HTTP router for Ruby
|
||||
|
||||
## v0.5.1 - 2016-01-19
|
||||
|
@ -6,18 +6,18 @@ Rack compatible HTTP router for Ruby
|
|||
|
||||
## v0.5.0 - 2016-01-12
|
||||
### Added
|
||||
- [Luca Guidi] Added `Lotus::Router#recognize` as a testing facility. Example `router.recognize('/') # => associated route`
|
||||
- [Luca Guidi] Added `Lotus::Router.define` in order to wrap routes definitions in `config/routes.rb` when `Lotus::Router` is used outside of Lotus projects
|
||||
- [David Strauß] Make `Lotus::Routing::Parsing::JsonParser` compatible with `application/vnd.api+json` MIME Type
|
||||
- [Alfonso Uceda Pompa] Improved exception messages for `Lotus::Router#path` and `#url`
|
||||
- [Luca Guidi] Added `Hanami::Router#recognize` as a testing facility. Example `router.recognize('/') # => associated route`
|
||||
- [Luca Guidi] Added `Hanami::Router.define` in order to wrap routes definitions in `config/routes.rb` when `Hanami::Router` is used outside of Hanami projects
|
||||
- [David Strauß] Make `Hanami::Routing::Parsing::JsonParser` compatible with `application/vnd.api+json` MIME Type
|
||||
- [Alfonso Uceda Pompa] Improved exception messages for `Hanami::Router#path` and `#url`
|
||||
|
||||
### Fixed
|
||||
- [Alfonso Uceda Pompa] Ensure `Lotus::Router#path` and `#url` to generate correct URL for mounted applications
|
||||
- [Alfonso Uceda Pompa] Ensure `Hanami::Router#path` and `#url` to generate correct URL for mounted applications
|
||||
- [Vladislav Zarakovsky] Ensure Force SSL mode to respect Rack SPEC
|
||||
|
||||
### Changed
|
||||
- [Alfonso Uceda Pompa] A failure for body parsers raises a `Lotus::Routing::Parsing::BodyParsingError` exception
|
||||
- [Karim Tarek] Introduced `Lotus::Router::Error` and let all the framework exceptions to inherit from it.
|
||||
- [Alfonso Uceda Pompa] A failure for body parsers raises a `Hanami::Routing::Parsing::BodyParsingError` exception
|
||||
- [Karim Tarek] Introduced `Hanami::Router::Error` and let all the framework exceptions to inherit from it.
|
||||
|
||||
## v0.4.3 - 2015-09-30
|
||||
### Added
|
||||
|
@ -30,7 +30,7 @@ Rack compatible HTTP router for Ruby
|
|||
|
||||
## v0.4.1 - 2015-06-23
|
||||
### Added
|
||||
- [Alfonso Uceda Pompa] Force SSL (eg `Lotus::Router.new(force_ssl: true`).
|
||||
- [Alfonso Uceda Pompa] Force SSL (eg `Hanami::Router.new(force_ssl: true`).
|
||||
- [Alfonso Uceda Pompa] Allow router to accept a `:prefix` option, in order to generate prefixed routes.
|
||||
|
||||
## v0.4.0 - 2015-05-15
|
||||
|
@ -44,7 +44,7 @@ Rack compatible HTTP router for Ruby
|
|||
|
||||
## v0.2.1 - 2015-01-30
|
||||
### Added
|
||||
- [Alfonso Uceda Pompa] Lotus::Action compat: invoke `.call` if defined, otherwise fall back to `#call`.
|
||||
- [Alfonso Uceda Pompa] Hanami::Action compat: invoke `.call` if defined, otherwise fall back to `#call`.
|
||||
|
||||
## v0.2.0 - 2014-12-23
|
||||
### Added
|
||||
|
@ -60,31 +60,31 @@ Rack compatible HTTP router for Ruby
|
|||
- [Luca Guidi] Fix RESTful resource(s) to respect :only/:except options
|
||||
|
||||
### Changed
|
||||
- [Luca Guidi] Aligned naming conventions with Lotus::Controller: no more BooksController::Index. Use Books::Index instead.
|
||||
- [Luca Guidi] Aligned naming conventions with Hanami::Controller: no more BooksController::Index. Use Books::Index instead.
|
||||
- [Luca Guidi] Removed `:prefix` option for routes. Use `#namespace` blocks instead.
|
||||
- [Janko Marohnić] Make 301 the default redirect status
|
||||
|
||||
## v0.1.1 - 2014-06-23
|
||||
### Added
|
||||
- [Luca Guidi] Introduced Lotus::Router#mount
|
||||
- [Luca Guidi] Let specify a pattern for Lotus::Routing::EndpointResolver
|
||||
- [Luca Guidi] Make Lotus::Routing::Endpoint::EndpointNotFound to inherit from StandardError, instead of Exception. This make it compatible with Rack::ShowExceptions.
|
||||
- [Luca Guidi] Introduced Hanami::Router#mount
|
||||
- [Luca Guidi] Let specify a pattern for Hanami::Routing::EndpointResolver
|
||||
- [Luca Guidi] Make Hanami::Routing::Endpoint::EndpointNotFound to inherit from StandardError, instead of Exception. This make it compatible with Rack::ShowExceptions.
|
||||
|
||||
## v0.1.0 - 2014-01-23
|
||||
### Added
|
||||
- [Luca Guidi] Official support for Ruby 2.1
|
||||
- [Luca Guidi] Added support for OPTIONS HTTP verb
|
||||
- [Luca Guidi] Added Lotus::Routing::EndpointNotFound when a lazy endpoint can't be found
|
||||
- [Luca Guidi] Make action separator customizable via Lotus::Router options.
|
||||
- [Luca Guidi] Catch http_router exceptions and re-raise them with names under Lotus::Routing. This helps to have a stable public API.
|
||||
- [Luca Guidi] Lotus::Routing::Resource::CollectionAction use configurable controller and action name separator over the hardcoded value
|
||||
- [Luca Guidi] Implemented Lotus::Routing::Namespace#resource
|
||||
- [Luca Guidi] Lotus::Routing::EndpointResolver now accepts options to inject namespace and suffix
|
||||
- [Luca Guidi] Added Hanami::Routing::EndpointNotFound when a lazy endpoint can't be found
|
||||
- [Luca Guidi] Make action separator customizable via Hanami::Router options.
|
||||
- [Luca Guidi] Catch http_router exceptions and re-raise them with names under Hanami::Routing. This helps to have a stable public API.
|
||||
- [Luca Guidi] Hanami::Routing::Resource::CollectionAction use configurable controller and action name separator over the hardcoded value
|
||||
- [Luca Guidi] Implemented Hanami::Routing::Namespace#resource
|
||||
- [Luca Guidi] Hanami::Routing::EndpointResolver now accepts options to inject namespace and suffix
|
||||
- [Luca Guidi] Allow resolver and route class to be injected via options
|
||||
- [Luca Guidi] Return 404 for not found and 405 for unacceptable HTTP method
|
||||
- [Luca Guidi] Allow non-finished Rack responses to be used
|
||||
- [Luca Guidi] Implemented lazy loading for endpoints
|
||||
- [Luca Guidi] Implemented Lotus::Router.new to take a block and define routes
|
||||
- [Luca Guidi] Implemented Hanami::Router.new to take a block and define routes
|
||||
- [Luca Guidi] Add support for resource
|
||||
- [Luca Guidi] Support for resource's member and collection
|
||||
- [Luca Guidi] Add support for namespaces
|
||||
|
|
|
@ -17,7 +17,7 @@ Here are some ways *you* can contribute:
|
|||
* by closing [issues][]
|
||||
* by reviewing patches
|
||||
|
||||
[issues]: https://github.com/lotus/router/issues
|
||||
[issues]: https://github.com/hanami/router/issues
|
||||
|
||||
## Submitting an Issue
|
||||
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
||||
|
|
6
Gemfile
6
Gemfile
|
@ -6,6 +6,6 @@ if !ENV['TRAVIS']
|
|||
gem 'yard', require: false
|
||||
end
|
||||
|
||||
gem 'lotus-utils', '~> 0.6', require: false, github: 'lotus/utils', branch: '0.6.x'
|
||||
gem 'simplecov', '~> 0.11', require: false
|
||||
gem 'coveralls', require: false
|
||||
gem 'hanami-utils', '~> 0.7', require: false, github: 'hanami/utils', branch: '0.7.x'
|
||||
gem 'simplecov', '~> 0.11', require: false
|
||||
gem 'coveralls', require: false
|
||||
|
|
155
README.md
155
README.md
|
@ -1,28 +1,28 @@
|
|||
# Lotus::Router
|
||||
# Hanami::Router
|
||||
|
||||
Rack compatible, lightweight and fast HTTP Router for Ruby and [Lotus](http://lotusrb.org).
|
||||
Rack compatible, lightweight and fast HTTP Router for Ruby and [Hanami](http://hanamirb.org).
|
||||
|
||||
## Status
|
||||
|
||||
[![Gem Version](http://img.shields.io/gem/v/lotus-router.svg)](https://badge.fury.io/rb/lotus-router)
|
||||
[![Build Status](http://img.shields.io/travis/lotus/router/master.svg)](https://travis-ci.org/lotus/router?branch=master)
|
||||
[![Coverage](http://img.shields.io/coveralls/lotus/router/master.svg)](https://coveralls.io/r/lotus/router)
|
||||
[![Code Climate](http://img.shields.io/codeclimate/github/lotus/router.svg)](https://codeclimate.com/github/lotus/router)
|
||||
[![Dependencies](http://img.shields.io/gemnasium/lotus/router.svg)](https://gemnasium.com/lotus/router)
|
||||
[![Inline docs](http://inch-ci.org/github/lotus/router.png)](http://inch-ci.org/github/lotus/router)
|
||||
[![Gem Version](http://img.shields.io/gem/v/hanami-router.svg)](https://badge.fury.io/rb/hanami-router)
|
||||
[![Build Status](http://img.shields.io/travis/hanami/router/master.svg)](https://travis-ci.org/hanami/router?branch=master)
|
||||
[![Coverage](http://img.shields.io/coveralls/hanami/router/master.svg)](https://coveralls.io/r/hanami/router)
|
||||
[![Code Climate](http://img.shields.io/codeclimate/github/hanami/router.svg)](https://codeclimate.com/github/hanami/router)
|
||||
[![Dependencies](http://img.shields.io/gemnasium/hanami/router.svg)](https://gemnasium.com/hanami/router)
|
||||
[![Inline docs](http://inch-ci.org/github/hanami/router.png)](http://inch-ci.org/github/hanami/router)
|
||||
|
||||
## Contact
|
||||
|
||||
* Home page: http://lotusrb.org
|
||||
* Mailing List: http://lotusrb.org/mailing-list
|
||||
* API Doc: http://rdoc.info/gems/lotus-router
|
||||
* Bugs/Issues: https://github.com/lotus/router/issues
|
||||
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby
|
||||
* Chat: https://gitter.im/lotus/chat
|
||||
* Home page: http://hanamirb.org
|
||||
* Mailing List: http://hanamirb.org/mailing-list
|
||||
* API Doc: http://rdoc.info/gems/hanami-router
|
||||
* Bugs/Issues: https://github.com/hanami/router/issues
|
||||
* Support: http://stackoverflow.com/questions/tagged/hanami
|
||||
* Chat: http://chat.hanamirb.org
|
||||
|
||||
## Rubies
|
||||
|
||||
__Lotus::Router__ supports Ruby (MRI) 2+, JRuby 9k+
|
||||
__Hanami::Router__ supports Ruby (MRI) 2+, JRuby 9k+
|
||||
|
||||
|
||||
## Installation
|
||||
|
@ -30,7 +30,7 @@ __Lotus::Router__ supports Ruby (MRI) 2+, JRuby 9k+
|
|||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'lotus-router'
|
||||
gem 'hanami-router'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
@ -42,16 +42,16 @@ $ bundle
|
|||
Or install it yourself as:
|
||||
|
||||
```shell
|
||||
$ gem install lotus-router
|
||||
$ gem install hanami-router
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
```ruby
|
||||
require 'lotus/router'
|
||||
require 'hanami/router'
|
||||
|
||||
app = Lotus::Router.new do
|
||||
get '/', to: ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
|
||||
app = Hanami::Router.new do
|
||||
get '/', to: ->(env) { [200, {}, ['Welcome to Hanami::Router!']] }
|
||||
end
|
||||
|
||||
Rack::Server.start app: app, Port: 2300
|
||||
|
@ -59,15 +59,15 @@ Rack::Server.start app: app, Port: 2300
|
|||
|
||||
## Usage
|
||||
|
||||
__Lotus::Router__ is designed to work as a standalone framework or within a
|
||||
context of a [Lotus](http://lotusrb.org) application.
|
||||
__Hanami::Router__ is designed to work as a standalone framework or within a
|
||||
context of a [Hanami](http://hanamirb.org) application.
|
||||
|
||||
For the standalone usage, it supports neat features:
|
||||
|
||||
### A Beautiful DSL:
|
||||
|
||||
```ruby
|
||||
Lotus::Router.new do
|
||||
Hanami::Router.new do
|
||||
get '/', to: ->(env) { [200, {}, ['Hi!']] }
|
||||
get '/dashboard', to: Dashboard::Index
|
||||
get '/rack-app', to: RackApp.new
|
||||
|
@ -109,8 +109,8 @@ end
|
|||
### Fixed string matching:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }
|
||||
router = Hanami::Router.new
|
||||
router.get '/hanami', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
|
||||
```
|
||||
|
||||
|
||||
|
@ -118,7 +118,7 @@ router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }
|
|||
### String matching with variables:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/flowers/:id', to: ->(env) { [200, {}, ["Hello from Flower no. #{ env['router.params'][:id] }!"]] }
|
||||
```
|
||||
|
||||
|
@ -127,7 +127,7 @@ router.get '/flowers/:id', to: ->(env) { [200, {}, ["Hello from Flower no. #{ en
|
|||
### Variables Constraints:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/flowers/:id', id: /\d+/, to: ->(env) { [200, {}, [":id must be a number!"]] }
|
||||
```
|
||||
|
||||
|
@ -136,7 +136,7 @@ router.get '/flowers/:id', id: /\d+/, to: ->(env) { [200, {}, [":id must be a nu
|
|||
### String matching with globbing:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/*', to: ->(env) { [200, {}, ["This is catch all: #{ env['router.params'].inspect }!"]] }
|
||||
```
|
||||
|
||||
|
@ -145,8 +145,8 @@ router.get '/*', to: ->(env) { [200, {}, ["This is catch all: #{ env['router.par
|
|||
### String matching with optional tokens:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router.get '/lotus(.:format)' to: ->(env) { [200, {}, ["You've requested #{ env['router.params'][:format] }!"]] }
|
||||
router = Hanami::Router.new
|
||||
router.get '/hanami(.:format)' to: ->(env) { [200, {}, ["You've requested #{ env['router.params'][:format] }!"]] }
|
||||
```
|
||||
|
||||
|
||||
|
@ -154,15 +154,15 @@ router.get '/lotus(.:format)' to: ->(env) { [200, {}, ["You've requested #{ env[
|
|||
### Support for the most common HTTP methods:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
endpoint = ->(env) { [200, {}, ['Hello from Lotus!']] }
|
||||
router = Hanami::Router.new
|
||||
endpoint = ->(env) { [200, {}, ['Hello from Hanami!']] }
|
||||
|
||||
router.get '/lotus', to: endpoint
|
||||
router.post '/lotus', to: endpoint
|
||||
router.put '/lotus', to: endpoint
|
||||
router.patch '/lotus', to: endpoint
|
||||
router.delete '/lotus', to: endpoint
|
||||
router.trace '/lotus', to: endpoint
|
||||
router.get '/hanami', to: endpoint
|
||||
router.post '/hanami', to: endpoint
|
||||
router.put '/hanami', to: endpoint
|
||||
router.patch '/hanami', to: endpoint
|
||||
router.delete '/hanami', to: endpoint
|
||||
router.trace '/hanami', to: endpoint
|
||||
```
|
||||
|
||||
|
||||
|
@ -170,7 +170,7 @@ router.trace '/lotus', to: endpoint
|
|||
### Redirect:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/redirect_destination', to: ->(env) { [200, {}, ['Redirect destination!']] }
|
||||
router.redirect '/legacy', to: '/redirect_destination'
|
||||
```
|
||||
|
@ -180,11 +180,11 @@ router.redirect '/legacy', to: '/redirect_destination'
|
|||
### Named routes:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org')
|
||||
router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }, as: :lotus
|
||||
router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org')
|
||||
router.get '/hanami', to: ->(env) { [200, {}, ['Hello from Hanami!']] }, as: :hanami
|
||||
|
||||
router.path(:lotus) # => "/lotus"
|
||||
router.url(:lotus) # => "https://lotusrb.org/lotus"
|
||||
router.path(:hanami) # => "/hanami"
|
||||
router.url(:hanami) # => "https://hanamirb.org/hanami"
|
||||
```
|
||||
|
||||
|
||||
|
@ -192,7 +192,7 @@ router.url(:lotus) # => "https://lotusrb.org/lotus"
|
|||
### Namespaced routes:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.namespace 'animals' do
|
||||
namespace 'mammals' do
|
||||
get '/cats', to: ->(env) { [200, {}, ['Meow!']] }, as: :cats
|
||||
|
@ -209,7 +209,7 @@ router.path(:animals_mammals_cats) # => "/animals/mammals/cats"
|
|||
### Mount Rack applications:
|
||||
|
||||
```ruby
|
||||
Lotus::Router.new do
|
||||
Hanami::Router.new do
|
||||
mount RackOne, at: '/rack1'
|
||||
mount RackTwo, at: '/rack2'
|
||||
mount RackThree.new, at: '/rack3'
|
||||
|
@ -222,7 +222,7 @@ end
|
|||
2. `RackTwo` is initialized, because it respond to `#call`
|
||||
3. `RackThree` is used as it is (object), because it respond to `#call`
|
||||
4. That Proc is used as it is, because it respond to `#call`
|
||||
5. That string is resolved as `Dashboard::Index` ([Lotus::Controller](https://github.com/lotus/controller) integration)
|
||||
5. That string is resolved as `Dashboard::Index` ([Hanami::Controller](https://github.com/hanami/controller) integration)
|
||||
|
||||
|
||||
|
||||
|
@ -231,8 +231,8 @@ end
|
|||
Everything that responds to `#call` is invoked as it is:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }
|
||||
router = Hanami::Router.new
|
||||
router.get '/hanami', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
|
||||
router.get '/middleware', to: Middleware
|
||||
router.get '/rack-app', to: RackApp.new
|
||||
router.get '/method', to: ActionControllerSubclass.action(:new)
|
||||
|
@ -248,8 +248,8 @@ class RackApp
|
|||
end
|
||||
end
|
||||
|
||||
router = Lotus::Router.new
|
||||
router.get '/lotus', to: 'rack_app' # it will map to RackApp.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/hanami', to: 'rack_app' # it will map to RackApp.new
|
||||
```
|
||||
|
||||
It also supports Controller + Action syntax:
|
||||
|
@ -263,7 +263,7 @@ module Flowers
|
|||
end
|
||||
end
|
||||
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.get '/flowers', to: 'flowers#index' # it will map to Flowers::Index.new
|
||||
```
|
||||
|
||||
|
@ -272,17 +272,17 @@ router.get '/flowers', to: 'flowers#index' # it will map to Flowers::Index.new
|
|||
### Implicit Not Found (404):
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.call(Rack::MockRequest.env_for('/unknown')).status # => 404
|
||||
```
|
||||
|
||||
### Controllers:
|
||||
|
||||
`Lotus::Router` has a special convention for controllers naming.
|
||||
`Hanami::Router` has a special convention for controllers naming.
|
||||
It allows to declare an action as an endpoint, with a special syntax: `<controller>#<action>`.
|
||||
|
||||
```ruby
|
||||
Lotus::Router.new do
|
||||
Hanami::Router.new do
|
||||
get '/', to: 'welcome#index'
|
||||
end
|
||||
```
|
||||
|
@ -292,14 +292,14 @@ In the example above, the router will look for the `Welcome::Index` action.
|
|||
#### Namespaces
|
||||
|
||||
In applications where for maintainability or technical reasons, this convention
|
||||
can't work, `Lotus::Router` can accept a `:namespace` option, which defines the
|
||||
can't work, `Hanami::Router` can accept a `:namespace` option, which defines the
|
||||
Ruby namespace where to look for actions.
|
||||
|
||||
For instance, given a Lotus full stack application called `Bookshelf`, the
|
||||
For instance, given a Hanami full stack application called `Bookshelf`, the
|
||||
controllers are available under `Bookshelf::Controllers`.
|
||||
|
||||
```ruby
|
||||
Lotus::Router.new(namespace: Bookshelf::Controllers) do
|
||||
Hanami::Router.new(namespace: Bookshelf::Controllers) do
|
||||
get '/', to: 'welcome#index'
|
||||
end
|
||||
```
|
||||
|
@ -309,7 +309,7 @@ In the example above, the router will look for the `Bookshelf::Controllers::Welc
|
|||
### RESTful Resource:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resource 'identity'
|
||||
```
|
||||
|
||||
|
@ -370,7 +370,7 @@ It will map:
|
|||
If you don't need all the default endpoints, just do:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resource 'identity', only: [:edit, :update]
|
||||
|
||||
#### which is equivalent to:
|
||||
|
@ -382,7 +382,7 @@ router.resource 'identity', except: [:show, :new, :create, :destroy]
|
|||
If you need extra endpoints:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resource 'identity' do
|
||||
member do
|
||||
get 'avatar' # maps to Identity::Avatar
|
||||
|
@ -401,7 +401,7 @@ router.path(:authorizations_identity) # => /identity/authorizations
|
|||
Configure controller:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resource 'profile', controller: 'identity'
|
||||
|
||||
router.path(:profile) # => /profile # Will route to Identity::Show
|
||||
|
@ -412,7 +412,7 @@ router.path(:profile) # => /profile # Will route to Identity::Show
|
|||
We can nest resource(s):
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resource :identity do
|
||||
resource :avatar
|
||||
resources :api_keys
|
||||
|
@ -433,7 +433,7 @@ router.path(:edit_identity_api_key) # => /identity/api_keys/:id/edit
|
|||
### RESTful Resources:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resources 'flowers'
|
||||
```
|
||||
|
||||
|
@ -510,7 +510,7 @@ router.path(:edit_flower, id: 23) # => /flowers/23/edit
|
|||
If you don't need all the default endpoints, just do:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resources 'flowers', only: [:new, :create, :show]
|
||||
|
||||
#### which is equivalent to:
|
||||
|
@ -522,7 +522,7 @@ router.resources 'flowers', except: [:index, :edit, :update, :destroy]
|
|||
If you need extra endpoints:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resources 'flowers' do
|
||||
member do
|
||||
get 'toggle' # maps to Flowers::Toggle
|
||||
|
@ -541,7 +541,7 @@ router.path(:search_flowers) # => /flowers/search
|
|||
Configure controller:
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resources 'blossoms', controller: 'flowers'
|
||||
|
||||
router.path(:blossom, id: 23) # => /blossoms/23 # Will route to Flowers::Show
|
||||
|
@ -552,7 +552,7 @@ router.path(:blossom, id: 23) # => /blossoms/23 # Will route to Flowers::Show
|
|||
We can nest resource(s):
|
||||
|
||||
```ruby
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.resources :users do
|
||||
resource :avatar
|
||||
resources :favorites
|
||||
|
@ -583,11 +583,11 @@ It comes with a built-in JSON parser and allows to pass custom parsers.
|
|||
#### JSON Parsing
|
||||
|
||||
```ruby
|
||||
require 'lotus/router'
|
||||
require 'hanami/router'
|
||||
|
||||
endpoint = ->(env) { [200, {},[env['router.params'].inspect]] }
|
||||
|
||||
router = Lotus::Router.new(parsers: [:json]) do
|
||||
router = Hanami::Router.new(parsers: [:json]) do
|
||||
patch '/books/:id', to: endpoint
|
||||
end
|
||||
```
|
||||
|
@ -605,15 +605,15 @@ curl http://localhost:2300/books/1 \
|
|||
If the json can't be parsed an exception is raised:
|
||||
|
||||
```ruby
|
||||
Lotus::Routing::Parsing::BodyParsingError
|
||||
Hanami::Routing::Parsing::BodyParsingError
|
||||
```
|
||||
|
||||
#### Custom Parsers
|
||||
|
||||
```ruby
|
||||
require 'lotus/router'
|
||||
require 'hanami/router'
|
||||
|
||||
# See Lotus::Routing::Parsing::Parser
|
||||
# See Hanami::Routing::Parsing::Parser
|
||||
class XmlParser
|
||||
def mime_types
|
||||
['application/xml', 'text/xml']
|
||||
|
@ -623,13 +623,13 @@ class XmlParser
|
|||
def parse(body)
|
||||
# parse xml
|
||||
rescue SomeXmlParsingError => e
|
||||
raise Lotus::Routing::Parsing::BodyParsingError.new(e)
|
||||
raise Hanami::Routing::Parsing::BodyParsingError.new(e)
|
||||
end
|
||||
end
|
||||
|
||||
endpoint = ->(env) { [200, {},[env['router.params'].inspect]] }
|
||||
|
||||
router = Lotus::Router.new(parsers: [XmlParser.new]) do
|
||||
router = Hanami::Router.new(parsers: [XmlParser.new]) do
|
||||
patch '/authors/:id', to: endpoint
|
||||
end
|
||||
```
|
||||
|
@ -647,9 +647,9 @@ curl http://localhost:2300/authors/1 \
|
|||
## Testing
|
||||
|
||||
```ruby
|
||||
require 'lotus/router'
|
||||
require 'hanami/router'
|
||||
|
||||
router = Lotus::Router.new do
|
||||
router = Hanami::Router.new do
|
||||
get '/books/:id', to: 'books#show', as: :book
|
||||
end
|
||||
|
||||
|
@ -672,7 +672,7 @@ route.routable? # => false
|
|||
|
||||
## Versioning
|
||||
|
||||
__Lotus::Router__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
||||
__Hanami::Router__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@ -690,3 +690,4 @@ Thanks to Joshua Hull ([@joshbuddy](https://github.com/joshbuddy)) for his
|
|||
## Copyright
|
||||
|
||||
Copyright © 2014-2016 Luca Guidi – Released under MIT License
|
||||
This project was formerly known as Lotus (`lotus-router`).
|
||||
|
|
|
@ -5,7 +5,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Callable
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating from callable endpoints' do
|
||||
|
|
|
@ -6,7 +6,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Callable
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating named routes' do
|
||||
|
@ -24,11 +24,11 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Class
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
$named_routes.each do |(name, _)|
|
||||
eval "#{ Lotus::Utils::String.new(name).classify } = Class.new($controller)"
|
||||
eval "#{ Hanami::Utils::String.new(name).classify } = Class.new($controller)"
|
||||
end
|
||||
|
||||
b.report 'generating named routes (class endpoints)' do
|
||||
|
@ -46,7 +46,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Lazy
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
$lazy = $lazy.map do |r|
|
||||
|
@ -60,7 +60,7 @@ Benchmark.bm(50) do |b|
|
|||
end
|
||||
|
||||
$lazy.each do |(name, _)|
|
||||
eval "#{ Lotus::Utils::String.new(name).classify } = Class.new($controller)"
|
||||
eval "#{ Hanami::Utils::String.new(name).classify } = Class.new($controller)"
|
||||
end
|
||||
|
||||
b.report 'recognizing routes (lazy endpoints)' do
|
||||
|
|
|
@ -5,7 +5,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Class
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating resource (class endpoints)' do
|
||||
|
@ -23,7 +23,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Lazy
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating resource (lazy endpoints)' do
|
||||
|
@ -33,7 +33,7 @@ Benchmark.bm(50) do |b|
|
|||
end
|
||||
|
||||
$lazy.each do |w|
|
||||
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
||||
eval "#{ Hanami::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
||||
end
|
||||
|
||||
b.report 'recognizing routes (lazy endpoints)' do
|
||||
|
|
|
@ -5,7 +5,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Class
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating resources (class endpoints)' do
|
||||
|
@ -30,7 +30,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Lazy
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating resources (lazy endpoints)' do
|
||||
|
@ -40,7 +40,7 @@ Benchmark.bm(50) do |b|
|
|||
end
|
||||
|
||||
$lazy.each do |w|
|
||||
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
||||
eval "#{ Hanami::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
||||
end
|
||||
|
||||
b.report 'recognizing resources (lazy endpoints)' do
|
||||
|
|
|
@ -6,7 +6,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Callable
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating routes' do
|
||||
|
@ -24,11 +24,11 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Class
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
$routes.each do |route|
|
||||
eval "#{ Lotus::Utils::String.new(route).classify } = Class.new($controller)"
|
||||
eval "#{ Hanami::Utils::String.new(route).classify } = Class.new($controller)"
|
||||
end
|
||||
|
||||
b.report 'generating routes (class endpoints)' do
|
||||
|
@ -46,7 +46,7 @@ Benchmark.bm(50) do |b|
|
|||
##
|
||||
# Lazy
|
||||
#
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
b.report 'generating routes (lazy endpoints)' do
|
||||
|
@ -56,7 +56,7 @@ Benchmark.bm(50) do |b|
|
|||
end
|
||||
|
||||
$lazy.each do |route|
|
||||
eval "#{ Lotus::Utils::String.new(route).classify } = Class.new($controller)"
|
||||
eval "#{ Hanami::Utils::String.new(route).classify } = Class.new($controller)"
|
||||
end
|
||||
|
||||
b.report 'recognizing routes (lazy endpoints)' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
$:.unshift 'lib'
|
||||
require 'benchmark'
|
||||
require 'lotus/router'
|
||||
require 'hanami/router'
|
||||
|
||||
# head -$((${RANDOM} % `wc -l < /usr/share/dict/words` + 1)) /usr/share/dict/words | tail -1
|
||||
|
||||
|
@ -46,11 +46,11 @@ $named_routes = $named_routes.map do |r|
|
|||
end
|
||||
|
||||
$resource.each do |w|
|
||||
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
||||
eval "#{ Hanami::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
||||
end
|
||||
|
||||
$resources.each do |w|
|
||||
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
||||
eval "#{ Hanami::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
||||
end
|
||||
|
||||
GC.start
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'lotus/router/version'
|
||||
require 'hanami/router/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = 'lotus-router'
|
||||
spec.version = Lotus::Router::VERSION
|
||||
spec.name = 'hanami-router'
|
||||
spec.version = Hanami::Router::VERSION
|
||||
spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda']
|
||||
spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com']
|
||||
spec.description = %q{Rack compatible HTTP router for Ruby}
|
||||
spec.summary = %q{Rack compatible HTTP router for Ruby and Lotus}
|
||||
spec.homepage = 'http://lotusrb.org'
|
||||
spec.summary = %q{Rack compatible HTTP router for Ruby and Hanami}
|
||||
spec.homepage = 'http://hanamirb.org'
|
||||
spec.license = 'MIT'
|
||||
|
||||
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md lotus-router.gemspec`.split($/)
|
||||
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-router.gemspec`.split($/)
|
||||
spec.executables = []
|
||||
spec.test_files = spec.files.grep(%r{^(test)/})
|
||||
spec.require_paths = ['lib']
|
||||
spec.required_ruby_version = '>= 2.0.0'
|
||||
|
||||
spec.add_dependency 'http_router', '~> 0.11'
|
||||
spec.add_dependency 'lotus-utils', '~> 0.6'
|
||||
spec.add_dependency 'hanami-utils', '~> 0.6'
|
||||
|
||||
spec.add_development_dependency 'bundler', '~> 1.5'
|
||||
spec.add_development_dependency 'minitest', '~> 5'
|
|
@ -0,0 +1 @@
|
|||
require 'hanami/router'
|
|
@ -1,20 +1,20 @@
|
|||
require 'rack/request'
|
||||
require 'lotus/routing/http_router'
|
||||
require 'lotus/routing/namespace'
|
||||
require 'lotus/routing/resource'
|
||||
require 'lotus/routing/resources'
|
||||
require 'lotus/routing/error'
|
||||
require 'hanami/routing/http_router'
|
||||
require 'hanami/routing/namespace'
|
||||
require 'hanami/routing/resource'
|
||||
require 'hanami/routing/resources'
|
||||
require 'hanami/routing/error'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
# Rack compatible, lightweight and fast HTTP Router.
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example It offers an intuitive DSL, that supports most of the HTTP verbs:
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
|
||||
# router = Lotus::Router.new do
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Hanami::Router!']] }
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: endpoint # => get and head requests
|
||||
# post '/', to: endpoint
|
||||
# put '/', to: endpoint
|
||||
|
@ -27,47 +27,47 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Specify an endpoint with `:to` (Rack compatible object)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
|
||||
# router = Lotus::Router.new do
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Hanami::Router!']] }
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: endpoint
|
||||
# end
|
||||
#
|
||||
# # :to is mandatory for the default resolver (`Lotus::Routing::EndpointResolver.new`),
|
||||
# # This behavior can be changed by passing a custom resolver to `Lotus::Router#initialize`
|
||||
# # :to is mandatory for the default resolver (`Hanami::Routing::EndpointResolver.new`),
|
||||
# # This behavior can be changed by passing a custom resolver to `Hanami::Router#initialize`
|
||||
#
|
||||
#
|
||||
#
|
||||
# @example Specify an endpoint with `:to` (controller and action string)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'articles#show' # => Articles::Show
|
||||
# end
|
||||
#
|
||||
# # This is a builtin feature for a Lotus::Controller convention.
|
||||
# # This is a builtin feature for a Hanami::Controller convention.
|
||||
#
|
||||
#
|
||||
#
|
||||
# @example Specify a named route with `:as`
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
|
||||
# router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org') do
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Hanami::Router!']] }
|
||||
# router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org') do
|
||||
# get '/', to: endpoint, as: :root
|
||||
# end
|
||||
#
|
||||
# router.path(:root) # => '/'
|
||||
# router.url(:root) # => 'https://lotusrb.org/'
|
||||
# router.url(:root) # => 'https://hanamirb.org/'
|
||||
#
|
||||
# # This isn't mandatory for the default route class (`Lotus::Routing::Route`),
|
||||
# # This behavior can be changed by passing a custom route to `Lotus::Router#initialize`
|
||||
# # This isn't mandatory for the default route class (`Hanami::Routing::Route`),
|
||||
# # This behavior can be changed by passing a custom route to `Hanami::Router#initialize`
|
||||
#
|
||||
# @example Mount an application
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# mount Api::App, at: '/api'
|
||||
# end
|
||||
#
|
||||
|
@ -78,11 +78,11 @@ module Lotus
|
|||
#
|
||||
# @since 0.5.0
|
||||
#
|
||||
# @see Lotus::Router#recognize
|
||||
# @see Lotus::Routing::RecognizedRoute
|
||||
# @see Lotus::Routing::RecognizedRoute#call
|
||||
# @see Lotus::Routing::RecognizedRoute#routable?
|
||||
class NotRoutableEndpointError < Lotus::Routing::Error
|
||||
# @see Hanami::Router#recognize
|
||||
# @see Hanami::Routing::RecognizedRoute
|
||||
# @see Hanami::Routing::RecognizedRoute#call
|
||||
# @see Hanami::Routing::RecognizedRoute#routable?
|
||||
class NotRoutableEndpointError < Hanami::Routing::Error
|
||||
REQUEST_METHOD = 'REQUEST_METHOD'.freeze
|
||||
PATH_INFO = 'PATH_INFO'.freeze
|
||||
|
||||
|
@ -93,7 +93,7 @@ module Lotus
|
|||
|
||||
# Returns the given block as it is.
|
||||
#
|
||||
# When Lotus::Router is used as a standalone gem and the routes are defined
|
||||
# When Hanami::Router is used as a standalone gem and the routes are defined
|
||||
# into a configuration file, some systems could raise an exception.
|
||||
#
|
||||
# Imagine the following file into a Ruby on Rails application:
|
||||
|
@ -103,10 +103,10 @@ module Lotus
|
|||
# Because Ruby on Rails in production mode use to eager load code and the
|
||||
# routes file uses top level method calls, it crashes the application.
|
||||
#
|
||||
# If we wrap these routes with <tt>Lotus::Router.define</tt>, the block
|
||||
# If we wrap these routes with <tt>Hanami::Router.define</tt>, the block
|
||||
# doesn't get yielded but just returned to the caller as it is.
|
||||
#
|
||||
# Usually the receiver of this block is <tt>Lotus::Router#initialize</tt>,
|
||||
# Usually the receiver of this block is <tt>Hanami::Router#initialize</tt>,
|
||||
# which finally evaluates the block.
|
||||
#
|
||||
# @param blk [Proc] a set of route definitions
|
||||
|
@ -117,7 +117,7 @@ module Lotus
|
|||
#
|
||||
# @example
|
||||
# # apps/web/config/routes.rb
|
||||
# Lotus::Router.define do
|
||||
# Hanami::Router.define do
|
||||
# get '/', to: 'home#index'
|
||||
# end
|
||||
def self.define(&blk)
|
||||
|
@ -132,9 +132,9 @@ module Lotus
|
|||
# @option options [String] :host The URL host (defaults to `"localhost"`)
|
||||
# @option options [String] :port The URL port (defaults to `"80"`)
|
||||
# @option options [Object, #resolve, #find, #action_separator] :resolver
|
||||
# the route resolver (defaults to `Lotus::Routing::EndpointResolver.new`)
|
||||
# the route resolver (defaults to `Hanami::Routing::EndpointResolver.new`)
|
||||
# @option options [Object, #generate] :route the route class
|
||||
# (defaults to `Lotus::Routing::Route`)
|
||||
# (defaults to `Hanami::Routing::Route`)
|
||||
# @option options [String] :action_separator the separator between controller
|
||||
# and action name (eg. 'dashboard#show', where '#' is the :action_separator)
|
||||
# @option options [Array<Symbol,String,Object #mime_types, parse>] :parsers
|
||||
|
@ -142,33 +142,33 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the optional block to define the routes
|
||||
#
|
||||
# @return [Lotus::Router] self
|
||||
# @return [Hanami::Router] self
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example Basic example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
|
||||
# endpoint = ->(env) { [200, {}, ['Welcome to Hanami::Router!']] }
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: endpoint
|
||||
#
|
||||
# # or
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: endpoint
|
||||
# end
|
||||
#
|
||||
# @example Body parsers
|
||||
# require 'json'
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# # It parses JSON body and makes the attributes available to the params
|
||||
#
|
||||
# endpoint = ->(env) { [200, {},[env['router.params'].inspect]] }
|
||||
#
|
||||
# router = Lotus::Router.new(parsers: [:json]) do
|
||||
# router = Hanami::Router.new(parsers: [:json]) do
|
||||
# patch '/books/:id', to: endpoint
|
||||
# end
|
||||
#
|
||||
|
@ -185,7 +185,7 @@ module Lotus
|
|||
# [200, {}, ["{:published=>\"true\",:id=>\"1\"}"]]
|
||||
#
|
||||
# @example Custom body parser
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# class XmlParser
|
||||
# def mime_types
|
||||
|
@ -202,7 +202,7 @@ module Lotus
|
|||
#
|
||||
# endpoint = ->(env) { [200, {},[env['router.params'].inspect]] }
|
||||
#
|
||||
# router = Lotus::Router.new(parsers: [XmlParser.new]) do
|
||||
# router = Hanami::Router.new(parsers: [XmlParser.new]) do
|
||||
# patch '/authors/:id', to: endpoint
|
||||
# end
|
||||
#
|
||||
|
@ -224,8 +224,8 @@ module Lotus
|
|||
|
||||
# Returns self
|
||||
#
|
||||
# This is a duck-typing trick for compatibility with `Lotus::Application`.
|
||||
# It's used by `Lotus::Routing::RoutesInspector` to inspect both apps and
|
||||
# This is a duck-typing trick for compatibility with `Hanami::Application`.
|
||||
# It's used by `Hanami::Routing::RoutesInspector` to inspect both apps and
|
||||
# routers.
|
||||
#
|
||||
# @return [self]
|
||||
|
@ -240,12 +240,12 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the block to define the routes
|
||||
#
|
||||
# @return [Lotus::Routing::Route]
|
||||
# @return [Hanami::Routing::Route]
|
||||
#
|
||||
# @since 0.2.0
|
||||
#
|
||||
# @example In Lotus framework
|
||||
# class Application < Lotus::Application
|
||||
# @example In Hanami framework
|
||||
# class Application < Hanami::Application
|
||||
# configure do
|
||||
# routes 'config/routes'
|
||||
# end
|
||||
|
@ -269,10 +269,10 @@ module Lotus
|
|||
#
|
||||
# @example
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.defined? # => false
|
||||
#
|
||||
# router = Lotus::Router.new { get '/', to: ->(env) { } }
|
||||
# router = Hanami::Router.new { get '/', to: ->(env) { } }
|
||||
# router.defined? # => true
|
||||
def defined?
|
||||
@router.routes.any?
|
||||
|
@ -287,21 +287,21 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example Fixed matching string
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/hanami', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
|
||||
#
|
||||
# @example String matching with variables
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/flowers/:id',
|
||||
# to: ->(env) {
|
||||
# [
|
||||
|
@ -312,17 +312,17 @@ module Lotus
|
|||
# }
|
||||
#
|
||||
# @example Variables Constraints
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/flowers/:id',
|
||||
# id: /\d+/,
|
||||
# to: ->(env) { [200, {}, [":id must be a number!"]] }
|
||||
#
|
||||
# @example String matching with globbling
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/*',
|
||||
# to: ->(env) {
|
||||
# [
|
||||
|
@ -333,31 +333,31 @@ module Lotus
|
|||
# }
|
||||
#
|
||||
# @example String matching with optional tokens
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router.get '/lotus(.:format)',
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/hanami(.:format)',
|
||||
# to: ->(env) {
|
||||
# [200, {}, ["You've requested #{ env['router.params'][:format] }!"]]
|
||||
# }
|
||||
#
|
||||
# @example Named routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org')
|
||||
# router.get '/lotus',
|
||||
# to: ->(env) { [200, {}, ['Hello from Lotus!']] },
|
||||
# as: :lotus
|
||||
# router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org')
|
||||
# router.get '/hanami',
|
||||
# to: ->(env) { [200, {}, ['Hello from Hanami!']] },
|
||||
# as: :hanami
|
||||
#
|
||||
# router.path(:lotus) # => "/lotus"
|
||||
# router.url(:lotus) # => "https://lotusrb.org/lotus"
|
||||
# router.path(:hanami) # => "/hanami"
|
||||
# router.url(:hanami) # => "https://hanamirb.org/hanami"
|
||||
#
|
||||
# @example Duck typed endpoints (Rack compatible objects)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
#
|
||||
# router.get '/lotus', to: ->(env) { [200, {}, ['Hello from Lotus!']] }
|
||||
# router.get '/hanami', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
|
||||
# router.get '/middleware', to: Middleware
|
||||
# router.get '/rack-app', to: RackApp.new
|
||||
# router.get '/method', to: ActionControllerSubclass.action(:new)
|
||||
|
@ -365,7 +365,7 @@ module Lotus
|
|||
# # Everything that responds to #call is invoked as it is
|
||||
#
|
||||
# @example Duck typed endpoints (strings)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# class RackApp
|
||||
# def call(env)
|
||||
|
@ -373,11 +373,11 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router.get '/lotus', to: 'rack_app' # it will map to RackApp.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/hanami', to: 'rack_app' # it will map to RackApp.new
|
||||
#
|
||||
# @example Duck typed endpoints (string: controller + action)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# module Flowers
|
||||
# class Index
|
||||
|
@ -387,11 +387,11 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/flowers', to: 'flowers#index'
|
||||
#
|
||||
# # It will map to Flowers::Index.new, which is the
|
||||
# # Lotus::Controller convention.
|
||||
# # Hanami::Controller convention.
|
||||
def get(path, options = {}, &blk)
|
||||
@router.get(path, options, &blk)
|
||||
end
|
||||
|
@ -405,10 +405,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def post(path, options = {}, &blk)
|
||||
|
@ -424,10 +424,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def put(path, options = {}, &blk)
|
||||
|
@ -443,10 +443,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def patch(path, options = {}, &blk)
|
||||
|
@ -462,10 +462,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def delete(path, options = {}, &blk)
|
||||
|
@ -481,10 +481,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def trace(path, options = {}, &blk)
|
||||
|
@ -500,10 +500,10 @@ module Lotus
|
|||
#
|
||||
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
|
||||
#
|
||||
# @return [Lotus::Routing::Route] this may vary according to the :route
|
||||
# @return [Hanami::Routing::Route] this may vary according to the :route
|
||||
# option passed to the constructor
|
||||
#
|
||||
# @see Lotus::Router#get
|
||||
# @see Hanami::Router#get
|
||||
#
|
||||
# @since 0.1.0
|
||||
def options(path, options = {}, &blk)
|
||||
|
@ -516,25 +516,25 @@ module Lotus
|
|||
# @param options [Hash] the options to customize the redirect behavior
|
||||
# @option options [Fixnum] the HTTP status to return (defaults to `301`)
|
||||
#
|
||||
# @return [Lotus::Routing::Route] the generated route.
|
||||
# @return [Hanami::Routing::Route] the generated route.
|
||||
# This may vary according to the `:route` option passed to the initializer
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Router
|
||||
# @see Hanami::Router
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# redirect '/legacy', to: '/new_endpoint'
|
||||
# redirect '/legacy2', to: '/new_endpoint2', code: 302
|
||||
# end
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.redirect '/legacy', to: '/new_endpoint'
|
||||
def redirect(path, options = {}, &endpoint)
|
||||
get(path).redirect @router.find(options), options[:code] || 301
|
||||
|
@ -549,25 +549,25 @@ module Lotus
|
|||
# be mounted
|
||||
# @param blk [Proc] the block that defines the resources
|
||||
#
|
||||
# @return [Lotus::Routing::Namespace] the generated namespace.
|
||||
# @return [Hanami::Routing::Namespace] the generated namespace.
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Router
|
||||
# @see Hanami::Router
|
||||
#
|
||||
# @example Basic example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# namespace 'trees' do
|
||||
# get '/sequoia', to: endpoint # => '/trees/sequoia'
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# @example Nested namespaces
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# namespace 'animals' do
|
||||
# namespace 'mammals' do
|
||||
# get '/cats', to: endpoint # => '/animals/mammals/cats'
|
||||
|
@ -576,9 +576,9 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.namespace 'trees' do
|
||||
# get '/sequoia', to: endpoint # => '/trees/sequoia'
|
||||
# end
|
||||
|
@ -587,7 +587,7 @@ module Lotus
|
|||
end
|
||||
|
||||
# Defines a set of named routes for a single RESTful resource.
|
||||
# It has a built-in integration for Lotus::Controller.
|
||||
# It has a built-in integration for Hanami::Controller.
|
||||
#
|
||||
# @param name [String] the name of the resource
|
||||
# @param options [Hash] a set of options to customize the routes
|
||||
|
@ -597,18 +597,18 @@ module Lotus
|
|||
# generated
|
||||
# @param blk [Proc] a block of code to generate additional routes
|
||||
#
|
||||
# @return [Lotus::Routing::Resource]
|
||||
# @return [Hanami::Routing::Resource]
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Routing::Resource
|
||||
# @see Lotus::Routing::Resource::Action
|
||||
# @see Lotus::Routing::Resource::Options
|
||||
# @see Hanami::Routing::Resource
|
||||
# @see Hanami::Routing::Resource::Action
|
||||
# @see Hanami::Routing::Resource::Options
|
||||
#
|
||||
# @example Default usage
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity'
|
||||
# end
|
||||
#
|
||||
|
@ -628,9 +628,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Limit the generated routes with :only
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity', only: [:show, :new, :create]
|
||||
# end
|
||||
#
|
||||
|
@ -647,9 +647,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Limit the generated routes with :except
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity', except: [:edit, :update, :destroy]
|
||||
# end
|
||||
#
|
||||
|
@ -666,9 +666,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Additional single routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity', only: [] do
|
||||
# member do
|
||||
# patch 'activate'
|
||||
|
@ -687,9 +687,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Additional collection routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity', only: [] do
|
||||
# collection do
|
||||
# get 'keys'
|
||||
|
@ -709,7 +709,7 @@ module Lotus
|
|||
end
|
||||
|
||||
# Defines a set of named routes for a plural RESTful resource.
|
||||
# It has a built-in integration for Lotus::Controller.
|
||||
# It has a built-in integration for Hanami::Controller.
|
||||
#
|
||||
# @param name [String] the name of the resource
|
||||
# @param options [Hash] a set of options to customize the routes
|
||||
|
@ -719,18 +719,18 @@ module Lotus
|
|||
# generated
|
||||
# @param blk [Proc] a block of code to generate additional routes
|
||||
#
|
||||
# @return [Lotus::Routing::Resources]
|
||||
# @return [Hanami::Routing::Resources]
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Routing::Resources
|
||||
# @see Lotus::Routing::Resources::Action
|
||||
# @see Lotus::Routing::Resource::Options
|
||||
# @see Hanami::Routing::Resources
|
||||
# @see Hanami::Routing::Resources::Action
|
||||
# @see Hanami::Routing::Resource::Options
|
||||
#
|
||||
# @example Default usage
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles'
|
||||
# end
|
||||
#
|
||||
|
@ -751,9 +751,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Limit the generated routes with :only
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles', only: [:index]
|
||||
# end
|
||||
#
|
||||
|
@ -768,9 +768,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Limit the generated routes with :except
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles', except: [:edit, :update]
|
||||
# end
|
||||
#
|
||||
|
@ -789,9 +789,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Additional single routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles', only: [] do
|
||||
# member do
|
||||
# patch 'publish'
|
||||
|
@ -810,9 +810,9 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Additional collection routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles', only: [] do
|
||||
# collection do
|
||||
# get 'search'
|
||||
|
@ -847,9 +847,9 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @example Basic usage
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# mount Api::App.new, at: '/api'
|
||||
# end
|
||||
#
|
||||
|
@ -861,9 +861,9 @@ module Lotus
|
|||
# # GET /api/unknown # => 404
|
||||
#
|
||||
# @example Difference between #get and #mount
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# get '/rack1', to: RackOne.new
|
||||
# mount RackTwo.new, at: '/rack2'
|
||||
# end
|
||||
|
@ -879,7 +879,7 @@ module Lotus
|
|||
# # POST /rack2 # => 200 (RackTwo.new)
|
||||
#
|
||||
# @example Types of mountable applications
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# class RackOne
|
||||
# def self.call(env)
|
||||
|
@ -903,7 +903,7 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# mount RackOne, at: '/rack1'
|
||||
# mount RackTwo, at: '/rack2'
|
||||
# mount RackThree.new, at: '/rack3'
|
||||
|
@ -915,7 +915,7 @@ module Lotus
|
|||
# # 2. RackTwo is initialized, because it respond to #call
|
||||
# # 3. RackThree is used as it is (object), because it respond to #call
|
||||
# # 4. That Proc is used as it is, because it respond to #call
|
||||
# # 5. That string is resolved as Dashboard::Index (Lotus::Controller)
|
||||
# # 5. That string is resolved as Dashboard::Index (Hanami::Controller)
|
||||
def mount(app, options)
|
||||
@router.mount(app, options)
|
||||
end
|
||||
|
@ -941,17 +941,17 @@ module Lotus
|
|||
# @param options [Hash] a set of options for Rack env or route params
|
||||
# @param params [Hash] a set of params
|
||||
#
|
||||
# @return [Lotus::Routing::RecognizedRoute] the recognized route
|
||||
# @return [Hanami::Routing::RecognizedRoute] the recognized route
|
||||
#
|
||||
# @since 0.5.0
|
||||
#
|
||||
# @see Lotus::Router#env_for
|
||||
# @see Lotus::Routing::RecognizedRoute
|
||||
# @see Hanami::Router#env_for
|
||||
# @see Hanami::Routing::RecognizedRoute
|
||||
#
|
||||
# @example Successful Path Recognition
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -961,9 +961,9 @@ module Lotus
|
|||
# route.params # => {:id=>"23"}
|
||||
#
|
||||
# @example Successful Rack Env Recognition
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -973,9 +973,9 @@ module Lotus
|
|||
# route.params # => {:id=>"23"}
|
||||
#
|
||||
# @example Successful Named Route Recognition
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -985,9 +985,9 @@ module Lotus
|
|||
# route.params # => {:id=>"23"}
|
||||
#
|
||||
# @example Failing Recognition For Unknown Path
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -996,9 +996,9 @@ module Lotus
|
|||
# route.routable? # => false
|
||||
#
|
||||
# @example Failing Recognition For Path With Wrong HTTP Verb
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -1007,9 +1007,9 @@ module Lotus
|
|||
# route.routable? # => false
|
||||
#
|
||||
# @example Failing Recognition For Rack Env With Wrong HTTP Verb
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -1018,9 +1018,9 @@ module Lotus
|
|||
# route.routable? # => false
|
||||
#
|
||||
# @example Failing Recognition Named Route With Wrong Params
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -1029,9 +1029,9 @@ module Lotus
|
|||
# route.routable? # => false
|
||||
#
|
||||
# @example Failing Recognition Named Route With Wrong HTTP Verb
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show', as: :book
|
||||
# end
|
||||
#
|
||||
|
@ -1040,7 +1040,7 @@ module Lotus
|
|||
# route.routable? # => false
|
||||
# route.params # => {:id=>"1"}
|
||||
def recognize(env, options = {}, params = nil)
|
||||
require 'lotus/routing/recognized_route'
|
||||
require 'hanami/routing/recognized_route'
|
||||
|
||||
env = env_for(env, options, params)
|
||||
responses, _ = *@router.recognize(env)
|
||||
|
@ -1058,15 +1058,15 @@ module Lotus
|
|||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @raise [Lotus::Routing::InvalidRouteException] when the router fails to
|
||||
# @raise [Hanami::Routing::InvalidRouteException] when the router fails to
|
||||
# recognize a route, because of the given arguments.
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org')
|
||||
# router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org')
|
||||
# router.get '/login', to: 'sessions#new', as: :login
|
||||
# router.get '/:name', to: 'frameworks#show', as: :framework
|
||||
#
|
||||
|
@ -1085,21 +1085,21 @@ module Lotus
|
|||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @raise [Lotus::Routing::InvalidRouteException] when the router fails to
|
||||
# @raise [Hanami::Routing::InvalidRouteException] when the router fails to
|
||||
# recognize a route, because of the given arguments.
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org')
|
||||
# router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org')
|
||||
# router.get '/login', to: 'sessions#new', as: :login
|
||||
# router.get '/:name', to: 'frameworks#show', as: :framework
|
||||
#
|
||||
# router.url(:login) # => "https://lotusrb.org/login"
|
||||
# router.url(:login, return_to: '/dashboard') # => "https://lotusrb.org/login?return_to=%2Fdashboard"
|
||||
# router.url(:framework, name: 'router') # => "https://lotusrb.org/router"
|
||||
# router.url(:login) # => "https://hanamirb.org/login"
|
||||
# router.url(:login, return_to: '/dashboard') # => "https://hanamirb.org/login?return_to=%2Fdashboard"
|
||||
# router.url(:framework, name: 'router') # => "https://hanamirb.org/router"
|
||||
def url(route, *args)
|
||||
@router.url(route, *args)
|
||||
end
|
||||
|
@ -1108,12 +1108,12 @@ module Lotus
|
|||
#
|
||||
# @since 0.2.0
|
||||
#
|
||||
# @see Lotus::Routing::RoutesInspector
|
||||
# @see Hanami::Routing::RoutesInspector
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'home#index'
|
||||
# get '/login', to: 'sessions#new', as: :login
|
||||
# post '/login', to: 'sessions#create'
|
||||
|
@ -1126,7 +1126,7 @@ module Lotus
|
|||
# POST /login Sessions::Create
|
||||
# logout GET, HEAD /logout Sessions::Destroy
|
||||
def inspector
|
||||
require 'lotus/routing/routes_inspector'
|
||||
require 'hanami/routing/routes_inspector'
|
||||
Routing::RoutesInspector.new(@router.routes)
|
||||
end
|
||||
|
||||
|
@ -1143,7 +1143,7 @@ module Lotus
|
|||
# @since 0.5.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#recognize
|
||||
# @see Hanami::Router#recognize
|
||||
# @see http://www.rubydoc.info/github/rack/rack/Rack%2FMockRequest.env_for
|
||||
def env_for(env, options = {}, params = nil)
|
||||
env = case env
|
||||
|
@ -1153,7 +1153,7 @@ module Lotus
|
|||
begin
|
||||
url = path(env, params || options)
|
||||
return env_for(url, options)
|
||||
rescue Lotus::Routing::InvalidRouteException
|
||||
rescue Hanami::Routing::InvalidRouteException
|
||||
{}
|
||||
end
|
||||
else
|
|
@ -1,6 +1,6 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
class Router
|
||||
# @since 0.1.0
|
||||
VERSION = '0.5.1'.freeze
|
||||
VERSION = '0.6.0'.freeze
|
||||
end
|
||||
end
|
|
@ -1,14 +1,14 @@
|
|||
require 'delegate'
|
||||
require 'lotus/routing/error'
|
||||
require 'lotus/utils/class'
|
||||
require 'hanami/routing/error'
|
||||
require 'hanami/utils/class'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Endpoint not found
|
||||
# This is raised when the router fails to load an endpoint at the runtime.
|
||||
#
|
||||
# @since 0.1.0
|
||||
class EndpointNotFound < Lotus::Routing::Error
|
||||
class EndpointNotFound < Hanami::Routing::Error
|
||||
end
|
||||
|
||||
# Routing endpoint
|
||||
|
@ -24,10 +24,10 @@ module Lotus
|
|||
# @api private
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# get '/proc', to: ->(env) { [200, {}, ['This will use Lotus::Routing::Endpoint']] }
|
||||
# Hanami::Router.new do
|
||||
# get '/proc', to: ->(env) { [200, {}, ['This will use Hanami::Routing::Endpoint']] }
|
||||
# get '/rack-app', to: RackApp.new
|
||||
# end
|
||||
class Endpoint < SimpleDelegator
|
||||
|
@ -54,8 +54,8 @@ module Lotus
|
|||
# The router will use this class for:
|
||||
#
|
||||
# * Classes
|
||||
# * Lotus::Action endpoints referenced as a class
|
||||
# * Lotus::Action endpoints referenced a string
|
||||
# * Hanami::Action endpoints referenced as a class
|
||||
# * Hanami::Action endpoints referenced a string
|
||||
# * RESTful resource(s)
|
||||
#
|
||||
# @since 0.1.0
|
||||
|
@ -63,12 +63,12 @@ module Lotus
|
|||
# @api private
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# get '/class', to: RackMiddleware
|
||||
# get '/lotus-action-class', to: Dashboard::Index
|
||||
# get '/lotus-action-string', to: 'dashboard#index'
|
||||
# get '/hanami-action-class', to: Dashboard::Index
|
||||
# get '/hanami-action-string', to: 'dashboard#index'
|
||||
#
|
||||
# resource 'identity'
|
||||
# resources 'articles'
|
||||
|
@ -100,7 +100,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Routing::ClassEndpoint
|
||||
# @see Hanami::Routing::ClassEndpoint
|
||||
class LazyEndpoint < Endpoint
|
||||
# Initialize the lazy endpoint
|
||||
#
|
|
@ -1,8 +1,8 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'lotus/utils/class'
|
||||
require 'lotus/routing/endpoint'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/utils/class'
|
||||
require 'hanami/routing/endpoint'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Resolve duck-typed endpoints
|
||||
#
|
||||
|
@ -23,9 +23,9 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'articles#show'
|
||||
# end
|
||||
ACTION_SEPARATOR = '#'.freeze
|
||||
|
@ -37,7 +37,7 @@ module Lotus
|
|||
# @param options [Hash] the options used to customize lookup behavior
|
||||
#
|
||||
# @option options [Class] :endpoint the endpoint class that is returned
|
||||
# by `#resolve`. (defaults to `Lotus::Routing::Endpoint`)
|
||||
# by `#resolve`. (defaults to `Hanami::Routing::Endpoint`)
|
||||
#
|
||||
# @option options [Class,Module] :namespace the Ruby namespace where to
|
||||
# lookup for controllers and actions. (defaults to `Object`)
|
||||
|
@ -51,23 +51,23 @@ module Lotus
|
|||
# @option options [String] :action_separator the sepatator between controller and
|
||||
# action name. (defaults to `ACTION_SEPARATOR`)
|
||||
#
|
||||
# @return [Lotus::Routing::EndpointResolver] self
|
||||
# @return [Hanami::Routing::EndpointResolver] self
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @example Specify custom endpoint class
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# resolver = Lotus::Routing::EndpointResolver.new(endpoint: CustomEndpoint)
|
||||
# router = Lotus::Router.new(resolver: resolver)
|
||||
# resolver = Hanami::Routing::EndpointResolver.new(endpoint: CustomEndpoint)
|
||||
# router = Hanami::Router.new(resolver: resolver)
|
||||
#
|
||||
# router.get('/', to: endpoint).dest # => #<CustomEndpoint:0x007f97f3359570 ...>
|
||||
#
|
||||
# @example Specify custom Ruby namespace
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# resolver = Lotus::Routing::EndpointResolver.new(namespace: MyApp)
|
||||
# router = Lotus::Router.new(resolver: resolver)
|
||||
# resolver = Hanami::Routing::EndpointResolver.new(namespace: MyApp)
|
||||
# router = Hanami::Router.new(resolver: resolver)
|
||||
#
|
||||
# router.get('/', to: 'articles#show')
|
||||
# # => Will look for: MyApp::Articles::Show
|
||||
|
@ -75,10 +75,10 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Specify custom pattern
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# resolver = Lotus::Routing::EndpointResolver.new(pattern: '%{controller}Controller::%{action}')
|
||||
# router = Lotus::Router.new(resolver: resolver)
|
||||
# resolver = Hanami::Routing::EndpointResolver.new(pattern: '%{controller}Controller::%{action}')
|
||||
# router = Hanami::Router.new(resolver: resolver)
|
||||
#
|
||||
# router.get('/', to: 'articles#show')
|
||||
# # => Will look for: ArticlesController::Show
|
||||
|
@ -86,10 +86,10 @@ module Lotus
|
|||
#
|
||||
#
|
||||
# @example Specify custom controller-action separator
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# resolver = Lotus::Routing::EndpointResolver.new(separator: '@')
|
||||
# router = Lotus::Router.new(resolver: resolver)
|
||||
# resolver = Hanami::Routing::EndpointResolver.new(separator: '@')
|
||||
# router = Hanami::Router.new(resolver: resolver)
|
||||
#
|
||||
# router.get('/', to: 'articles@show')
|
||||
# # => Will look for: Articles::Show
|
||||
|
@ -118,39 +118,39 @@ module Lotus
|
|||
# @see #find
|
||||
#
|
||||
# @example Resolve to a Proc
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: ->(env) { [200, {}, ['Hi!']] }
|
||||
#
|
||||
# @example Resolve to a class
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: RackMiddleware
|
||||
#
|
||||
# @example Resolve to a Rack compatible object (respond to #call)
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: AnotherMiddleware.new
|
||||
#
|
||||
# @example Resolve to a Lotus::Action from a string (see Lotus::Controller framework)
|
||||
# require 'lotus/router'
|
||||
# @example Resolve to a Hanami::Action from a string (see Hanami::Controller framework)
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: 'articles#show'
|
||||
#
|
||||
# @example Resolve to a Lotus::Action (see Lotus::Controller framework)
|
||||
# require 'lotus/router'
|
||||
# @example Resolve to a Hanami::Action (see Hanami::Controller framework)
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get '/', to: Articles::Show
|
||||
#
|
||||
# @example Resolve a redirect with a namespace
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.namespace 'users' do
|
||||
# get '/home', to: ->(env) { ... }
|
||||
# redirect '/dashboard', to: '/home'
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# @since 0.5.0
|
||||
class Error < ::StandardError
|
|
@ -1,6 +1,6 @@
|
|||
require 'rack/request'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Force ssl
|
||||
#
|
||||
|
@ -106,7 +106,7 @@ module Lotus
|
|||
#
|
||||
# @return [Array]
|
||||
#
|
||||
# @see Lotus::Routing::HttpRouter#call
|
||||
# @see Hanami::Routing::HttpRouter#call
|
||||
#
|
||||
# @since 0.4.1
|
||||
# @api private
|
|
@ -1,31 +1,31 @@
|
|||
require 'http_router'
|
||||
require 'lotus/utils/io'
|
||||
require 'lotus/routing/endpoint_resolver'
|
||||
require 'lotus/routing/route'
|
||||
require 'lotus/routing/parsers'
|
||||
require 'lotus/routing/force_ssl'
|
||||
require 'lotus/routing/error'
|
||||
require 'lotus/utils/path_prefix'
|
||||
require 'hanami/utils/io'
|
||||
require 'hanami/routing/endpoint_resolver'
|
||||
require 'hanami/routing/route'
|
||||
require 'hanami/routing/parsers'
|
||||
require 'hanami/routing/force_ssl'
|
||||
require 'hanami/routing/error'
|
||||
require 'hanami/utils/path_prefix'
|
||||
|
||||
Lotus::Utils::IO.silence_warnings do
|
||||
Hanami::Utils::IO.silence_warnings do
|
||||
HttpRouter::Route::VALID_HTTP_VERBS = %w{GET POST PUT PATCH DELETE HEAD OPTIONS TRACE}
|
||||
end
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Invalid route
|
||||
# This is raised when the router fails to recognize a route, because of the
|
||||
# given arguments.
|
||||
#
|
||||
# @since 0.1.0
|
||||
class InvalidRouteException < Lotus::Routing::Error
|
||||
class InvalidRouteException < Hanami::Routing::Error
|
||||
end
|
||||
|
||||
# HTTP router
|
||||
#
|
||||
# This implementation is based on ::HttpRouter (http_router gem).
|
||||
#
|
||||
# Lotus::Router wraps an instance of this class, in order to protect its
|
||||
# Hanami::Router wraps an instance of this class, in order to protect its
|
||||
# public API from any future change of ::HttpRouter.
|
||||
#
|
||||
# @since 0.1.0
|
||||
|
@ -43,7 +43,7 @@ module Lotus
|
|||
|
||||
# Initialize the router.
|
||||
#
|
||||
# @see Lotus::Router#initialize
|
||||
# @see Hanami::Router#initialize
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -58,12 +58,12 @@ module Lotus
|
|||
@resolver = options[:resolver] || Routing::EndpointResolver.new(options)
|
||||
@parsers = Routing::Parsers.new(options[:parsers])
|
||||
@prefix = Utils::PathPrefix.new(options[:prefix] || '')
|
||||
@force_ssl = Lotus::Routing::ForceSsl.new(!!options[:force_ssl], host: @default_host, port: @default_port)
|
||||
@force_ssl = Hanami::Routing::ForceSsl.new(!!options[:force_ssl], host: @default_host, port: @default_port)
|
||||
end
|
||||
|
||||
# Separator between controller and action name.
|
||||
#
|
||||
# @see Lotus::Routing::EndpointResolver::ACTION_SEPARATOR
|
||||
# @see Hanami::Routing::EndpointResolver::ACTION_SEPARATOR
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -73,7 +73,7 @@ module Lotus
|
|||
|
||||
# Finds a path from the given options.
|
||||
#
|
||||
# @see Lotus::Routing::EndpointResolver#find
|
||||
# @see Hanami::Routing::EndpointResolver#find
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -83,7 +83,7 @@ module Lotus
|
|||
|
||||
# Generate a relative URL for a specified named route.
|
||||
#
|
||||
# @see Lotus::Router#path
|
||||
# @see Hanami::Router#path
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -95,7 +95,7 @@ module Lotus
|
|||
|
||||
# Generate an absolute URL for a specified named route.
|
||||
#
|
||||
# @see Lotus::Router#path
|
||||
# @see Hanami::Router#path
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -107,7 +107,7 @@ module Lotus
|
|||
|
||||
# Support for OPTIONS HTTP verb
|
||||
#
|
||||
# @see Lotus::Router#options
|
||||
# @see Hanami::Router#options
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
@ -117,7 +117,7 @@ module Lotus
|
|||
|
||||
# Allow to mount a Rack app
|
||||
#
|
||||
# @see Lotus::Router#mount
|
||||
# @see Hanami::Router#mount
|
||||
#
|
||||
# @since 0.1.1
|
||||
# @api private
|
|
@ -1,16 +1,16 @@
|
|||
require 'delegate'
|
||||
require 'lotus/utils/path_prefix'
|
||||
require 'hanami/utils/path_prefix'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Namespace for routes.
|
||||
# Implementation of Lotus::Router#namespace
|
||||
# Implementation of Hanami::Router#namespace
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#namespace
|
||||
# @see Hanami::Router#namespace
|
||||
class Namespace < SimpleDelegator
|
||||
# @api private
|
||||
# @since 0.1.0
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/routing/parsing/parser'
|
||||
require 'hanami/routing/parsing/parser'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
class Parsers
|
||||
CONTENT_TYPE = 'CONTENT_TYPE'.freeze
|
|
@ -1,6 +1,6 @@
|
|||
require 'json'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
module Parsing
|
||||
class JsonParser < Parser
|
||||
|
@ -14,7 +14,7 @@ module Lotus
|
|||
#
|
||||
# @return [Hash] the parsed json
|
||||
#
|
||||
# @raise [Lotus::Routing::Parsing::BodyParsingError] when the body can't be parsed.
|
||||
# @raise [Hanami::Routing::Parsing::BodyParsingError] when the body can't be parsed.
|
||||
#
|
||||
# @since 0.2.0
|
||||
def parse(body)
|
|
@ -1,19 +1,19 @@
|
|||
require 'lotus/utils/class'
|
||||
require 'lotus/utils/string'
|
||||
require 'lotus/routing/error'
|
||||
require 'hanami/utils/class'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/routing/error'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
module Parsing
|
||||
# Body parsing error
|
||||
# This is raised when parser fails to parse the body
|
||||
#
|
||||
# @since 0.5.0
|
||||
class BodyParsingError < Lotus::Routing::Error
|
||||
class BodyParsingError < Hanami::Routing::Error
|
||||
end
|
||||
|
||||
# @since 0.2.0
|
||||
class UnknownParserError < Lotus::Routing::Error
|
||||
class UnknownParserError < Hanami::Routing::Error
|
||||
def initialize(parser)
|
||||
super("Unknown Parser: `#{ parser }'")
|
||||
end
|
||||
|
@ -45,10 +45,10 @@ module Lotus
|
|||
# @since 0.2.0
|
||||
# @api private
|
||||
def self.require_parser(parser)
|
||||
require "lotus/routing/parsing/#{ parser }_parser"
|
||||
require "hanami/routing/parsing/#{ parser }_parser"
|
||||
|
||||
parser = Utils::String.new(parser).classify
|
||||
Utils::Class.load!("Lotus::Routing::Parsing::#{ parser }Parser").new
|
||||
Utils::Class.load!("Hanami::Routing::Parsing::#{ parser }Parser").new
|
||||
rescue LoadError, NameError
|
||||
raise UnknownParserError.new(parser)
|
||||
end
|
|
@ -1,12 +1,12 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'hanami/utils/string'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Represents a result of router path recognition.
|
||||
#
|
||||
# @since 0.5.0
|
||||
#
|
||||
# @see Lotus::Router#recognize
|
||||
# @see Hanami::Router#recognize
|
||||
class RecognizedRoute
|
||||
# @since 0.5.0
|
||||
# @api private
|
||||
|
@ -32,9 +32,9 @@ module Lotus
|
|||
#
|
||||
# @param response [HttpRouter::Response] raw response of recognition
|
||||
# @param env [Hash] Rack env
|
||||
# @param router [Lotus::Routing::HttpRouter] low level router
|
||||
# @param router [Hanami::Routing::HttpRouter] low level router
|
||||
#
|
||||
# @return [Lotus::Routing::RecognizedRoute]
|
||||
# @return [Hanami::Routing::RecognizedRoute]
|
||||
#
|
||||
# @since 0.5.0
|
||||
# @api private
|
||||
|
@ -56,18 +56,18 @@ module Lotus
|
|||
#
|
||||
# @return [Array] serialized Rack response
|
||||
#
|
||||
# @raise [Lotus::Router::NotRoutableEndpointError] if not routable
|
||||
# @raise [Hanami::Router::NotRoutableEndpointError] if not routable
|
||||
#
|
||||
# @since 0.5.0
|
||||
# @api public
|
||||
#
|
||||
# @see Lotus::Routing::RecognizedRoute#routable?
|
||||
# @see Lotus::Router::NotRoutableEndpointError
|
||||
# @see Hanami::Routing::RecognizedRoute#routable?
|
||||
# @see Hanami::Router::NotRoutableEndpointError
|
||||
def call(env)
|
||||
if routable?
|
||||
@endpoint.call(env)
|
||||
else
|
||||
raise Lotus::Router::NotRoutableEndpointError.new(@env)
|
||||
raise Hanami::Router::NotRoutableEndpointError.new(@env)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,12 +88,12 @@ module Lotus
|
|||
# @since 0.5.0
|
||||
# @api public
|
||||
#
|
||||
# @see Lotus::Router#recognize
|
||||
# @see Hanami::Router#recognize
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/books/:id', to: 'books#show'
|
||||
# end
|
||||
#
|
||||
|
@ -102,7 +102,7 @@ module Lotus
|
|||
namespace = NAMESPACE % @namespace
|
||||
|
||||
if destination.match(namespace)
|
||||
Lotus::Utils::String.new(
|
||||
Hanami::Utils::String.new(
|
||||
destination.sub(namespace, NAMESPACE_REPLACEMENT)
|
||||
).underscore.rsub(ACTION_PATH_SEPARATOR, @action_separator)
|
||||
else
|
||||
|
@ -117,12 +117,12 @@ module Lotus
|
|||
# @since 0.5.0
|
||||
# @api public
|
||||
#
|
||||
# @see Lotus::Router#recognize
|
||||
# @see Hanami::Router#recognize
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'home#index'
|
||||
# end
|
||||
#
|
||||
|
@ -137,7 +137,7 @@ module Lotus
|
|||
# @since 0.5.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Routing::Endpoint
|
||||
# @see Hanami::Routing::Endpoint
|
||||
def destination
|
||||
@destination ||= begin
|
||||
case k = @endpoint.__getobj__
|
|
@ -1,17 +1,17 @@
|
|||
require 'lotus/utils/class_attribute'
|
||||
require 'lotus/routing/resource/options'
|
||||
require 'lotus/routing/resource/action'
|
||||
require 'hanami/utils/class_attribute'
|
||||
require 'hanami/routing/resource/options'
|
||||
require 'hanami/routing/resource/action'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Set of RESTful resource routes
|
||||
# Implementation of Lotus::Router#resource
|
||||
# Implementation of Hanami::Router#resource
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Resource
|
||||
include Utils::ClassAttribute
|
||||
|
||||
|
@ -65,7 +65,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.4.0
|
||||
#
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
def resources(name, options = {}, &blk)
|
||||
_resource(Resources, name, options, &blk)
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.4.0
|
||||
#
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
def resource(name, options = {}, &blk)
|
||||
_resource(Resource, name, options, &blk)
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'lotus/utils/path_prefix'
|
||||
require 'lotus/utils/class_attribute'
|
||||
require 'lotus/routing/resource/nested'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/utils/path_prefix'
|
||||
require 'hanami/utils/class_attribute'
|
||||
require 'hanami/routing/resource/nested'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
class Resource
|
||||
# Action for RESTful resource
|
||||
|
@ -12,7 +12,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Action
|
||||
include Utils::ClassAttribute
|
||||
|
||||
|
@ -45,10 +45,10 @@ module Lotus
|
|||
|
||||
# Generate an action for the given router
|
||||
#
|
||||
# @param router [Lotus::Router]
|
||||
# @param action [Lotus::Routing::Resource::Action]
|
||||
# @param router [Hanami::Router]
|
||||
# @param action [Hanami::Routing::Resource::Action]
|
||||
# @param options [Hash]
|
||||
# @param resource [Lotus::Routing::Resource, Lotus::Routing::Resources]
|
||||
# @param resource [Hanami::Routing::Resource, Hanami::Routing::Resources]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
|
@ -59,9 +59,9 @@ module Lotus
|
|||
|
||||
# Initialize an action
|
||||
#
|
||||
# @param router [Lotus::Router]
|
||||
# @param router [Hanami::Router]
|
||||
# @param options [Hash]
|
||||
# @param resource [Lotus::Routing::Resource, Lotus::Routing::Resources]
|
||||
# @param resource [Hanami::Routing::Resource, Hanami::Routing::Resources]
|
||||
# @param blk [Proc]
|
||||
#
|
||||
# @api private
|
||||
|
@ -94,9 +94,9 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resource 'identity'
|
||||
# end
|
||||
#
|
||||
|
@ -119,8 +119,8 @@ module Lotus
|
|||
# @param action [String] the action name
|
||||
#
|
||||
# @example
|
||||
# Lotus::Routing::Resource::Action.send(:class_for, 'New') # =>
|
||||
# Lotus::Routing::Resource::New
|
||||
# Hanami::Routing::Resource::Action.send(:class_for, 'New') # =>
|
||||
# Hanami::Routing::Resource::New
|
||||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
|
@ -130,7 +130,7 @@ module Lotus
|
|||
|
||||
# Accepted HTTP verb
|
||||
#
|
||||
# @see Lotus::Routing::Resource::Action.verb
|
||||
# @see Hanami::Routing::Resource::Action.verb
|
||||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
|
@ -141,9 +141,9 @@ module Lotus
|
|||
# The namespaced URL relative path
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'flowers'
|
||||
#
|
||||
# namespace 'animals' do
|
||||
|
@ -176,9 +176,9 @@ module Lotus
|
|||
# The namespaced name of the action within the whole context of the router.
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'flowers'
|
||||
#
|
||||
# namespace 'animals' do
|
||||
|
@ -211,7 +211,7 @@ module Lotus
|
|||
# A string that represents the endpoint to be loaded.
|
||||
# It is composed by controller and action name.
|
||||
#
|
||||
# @see Lotus::Routing::Resource::Action#separator
|
||||
# @see Hanami::Routing::Resource::Action#separator
|
||||
#
|
||||
# @example
|
||||
# 'flowers#index'
|
||||
|
@ -224,7 +224,7 @@ module Lotus
|
|||
|
||||
# Separator between controller and action name
|
||||
#
|
||||
# @see Lotus::Routing::EndpointResolver#separator
|
||||
# @see Hanami::Routing::EndpointResolver#separator
|
||||
#
|
||||
# @example
|
||||
# '#' # default
|
||||
|
@ -238,7 +238,7 @@ module Lotus
|
|||
# Resource controller name
|
||||
#
|
||||
# @example
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'flowers', controller: 'rocks'
|
||||
# end
|
||||
#
|
||||
|
@ -259,7 +259,7 @@ module Lotus
|
|||
# @since 0.4.0
|
||||
def _singularized_as
|
||||
resource_name.split(NESTED_ROUTES_SEPARATOR).map do |name|
|
||||
Lotus::Utils::String.new(name).singularize
|
||||
Hanami::Utils::String.new(name).singularize
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -277,7 +277,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class CollectionAction < Action
|
||||
def generate(&blk)
|
||||
instance_eval(&blk) if block_given?
|
||||
|
@ -311,7 +311,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class MemberAction < CollectionAction
|
||||
end
|
||||
|
||||
|
@ -334,7 +334,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class New < Action
|
||||
include DefaultMemberAction
|
||||
end
|
||||
|
@ -343,7 +343,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Create < Action
|
||||
self.verb = :post
|
||||
end
|
||||
|
@ -352,7 +352,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Show < Action
|
||||
end
|
||||
|
||||
|
@ -360,7 +360,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Edit < Action
|
||||
include DefaultMemberAction
|
||||
end
|
||||
|
@ -369,7 +369,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Update < Action
|
||||
self.verb = :patch
|
||||
end
|
||||
|
@ -378,7 +378,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resource
|
||||
# @see Hanami::Router#resource
|
||||
class Destroy < Action
|
||||
self.verb = :delete
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
class Resource
|
||||
# Helper class to calculate nested path
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
class Resource
|
||||
# Options for RESTFul resource(s)
|
||||
|
@ -6,16 +6,16 @@ module Lotus
|
|||
# @api private
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Router#resource
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resource
|
||||
# @see Hanami::Router#resources
|
||||
class Options
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
attr_reader :actions
|
||||
|
||||
# Initialize the options for:
|
||||
# * Lotus::Router#resource
|
||||
# * Lotus::Router#resources
|
||||
# * Hanami::Router#resource
|
||||
# * Hanami::Router#resources
|
||||
#
|
||||
# @param actions [Array<Symbol>] the name of the actions
|
||||
# @param options [Hash]
|
||||
|
@ -26,13 +26,13 @@ module Lotus
|
|||
# @api private
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Routing::Resource
|
||||
# @see Lotus::Routing::Resources
|
||||
# @see Hanami::Routing::Resource
|
||||
# @see Hanami::Routing::Resources
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# Lotus::Router.new do
|
||||
# Hanami::Router.new do
|
||||
# resources 'articles', only: [:index]
|
||||
# resource 'profile', except: [:new, :create, :destroy]
|
||||
# end
|
|
@ -1,16 +1,16 @@
|
|||
require 'lotus/routing/resource'
|
||||
require 'lotus/routing/resources/action'
|
||||
require 'hanami/routing/resource'
|
||||
require 'hanami/routing/resources/action'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Set of RESTful resources routes
|
||||
# Implementation of Lotus::Router#resources
|
||||
# Implementation of Hanami::Router#resources
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Resources < Resource
|
||||
# Set of default routes
|
||||
#
|
||||
|
@ -41,7 +41,7 @@ module Lotus
|
|||
# @api private
|
||||
# @since 0.4.0
|
||||
def wildcard_param(route_param = nil)
|
||||
"/:#{ Lotus::Utils::String.new(route_param).singularize }_id/"
|
||||
"/:#{ Hanami::Utils::String.new(route_param).singularize }_id/"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'lotus/utils/path_prefix'
|
||||
require 'lotus/routing/resource'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/utils/path_prefix'
|
||||
require 'hanami/routing/resource'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
class Resources < Resource
|
||||
# Action for RESTful resources
|
||||
|
@ -11,7 +11,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Action < Resource::Action
|
||||
# Ruby namespace where lookup for default subclasses.
|
||||
#
|
||||
|
@ -38,7 +38,7 @@ module Lotus
|
|||
# @api private
|
||||
# @since 0.4.0
|
||||
def as
|
||||
Lotus::Utils::String.new(super).pluralize
|
||||
Hanami::Utils::String.new(super).pluralize
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,10 +47,10 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class CollectionAction < Resource::CollectionAction
|
||||
def as(action_name)
|
||||
Lotus::Utils::String.new(super(action_name)).pluralize
|
||||
Hanami::Utils::String.new(super(action_name)).pluralize
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -59,7 +59,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class MemberAction < Resource::MemberAction
|
||||
private
|
||||
def path(action_name)
|
||||
|
@ -82,7 +82,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Index < Action
|
||||
include PluralizedAction
|
||||
self.verb = :get
|
||||
|
@ -92,7 +92,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class New < Resource::New
|
||||
end
|
||||
|
||||
|
@ -100,7 +100,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Create < Resource::Create
|
||||
include PluralizedAction
|
||||
end
|
||||
|
@ -109,7 +109,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Show < Resource::Show
|
||||
include DefaultMemberAction
|
||||
end
|
||||
|
@ -118,7 +118,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Edit < Resource::Edit
|
||||
include DefaultMemberAction
|
||||
|
||||
|
@ -132,7 +132,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Update < Resource::Update
|
||||
include DefaultMemberAction
|
||||
end
|
||||
|
@ -141,7 +141,7 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
# @see Lotus::Router#resources
|
||||
# @see Hanami::Router#resources
|
||||
class Destroy < Resource::Destroy
|
||||
include DefaultMemberAction
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'http_router/route'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Entry of the routing system
|
||||
#
|
||||
|
@ -11,16 +11,16 @@ module Lotus
|
|||
# @see http://rdoc.info/gems/http_router/HttpRouter/Route
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router.get('/', to: endpoint) # => #<Lotus::Routing::Route:0x007f83083ba028 ...>
|
||||
# router = Hanami::Router.new
|
||||
# router.get('/', to: endpoint) # => #<Hanami::Routing::Route:0x007f83083ba028 ...>
|
||||
class Route < HttpRouter::Route
|
||||
# Asks the given resolver to return an endpoint that will be associated
|
||||
# with the other options.
|
||||
#
|
||||
# @param resolver [Lotus::Routing::EndpointResolver, #resolve] this may change
|
||||
# according to the :resolve option passed to Lotus::Router#initialize.
|
||||
# @param resolver [Hanami::Routing::EndpointResolver, #resolve] this may change
|
||||
# according to the :resolve option passed to Hanami::Router#initialize.
|
||||
#
|
||||
# @param options [Hash] options to customize the route
|
||||
# @option options [Symbol] :as the name we want to use for the route
|
||||
|
@ -29,12 +29,12 @@ module Lotus
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Router#initialize
|
||||
# @see Hanami::Router#initialize
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new
|
||||
# router = Hanami::Router.new
|
||||
# router.get('/', to: endpoint, as: :home_page).name # => :home_page
|
||||
#
|
||||
# router.path(:home_page) # => '/'
|
||||
|
@ -45,7 +45,7 @@ module Lotus
|
|||
end
|
||||
|
||||
# Introspect the given route to understand if there is a wrapped
|
||||
# Lotus::Router
|
||||
# Hanami::Router
|
||||
#
|
||||
# @since 0.2.0
|
||||
# @api private
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/path_prefix'
|
||||
require 'hanami/utils/path_prefix'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Routing
|
||||
# Routes inspector
|
||||
#
|
||||
|
@ -43,7 +43,7 @@ module Lotus
|
|||
|
||||
# Instantiate a new inspector
|
||||
#
|
||||
# @return [Lotus::Routing::RoutesInspector] the new instance
|
||||
# @return [Hanami::Routing::RoutesInspector] the new instance
|
||||
#
|
||||
# @since 0.2.0
|
||||
# @api private
|
||||
|
@ -60,12 +60,12 @@ module Lotus
|
|||
#
|
||||
# @since 0.2.0
|
||||
#
|
||||
# @see Lotus::Routing::RoutesInspector::FORMATTER
|
||||
# @see Hanami::Routing::RoutesInspector::FORMATTER
|
||||
#
|
||||
# @example Default formatter
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'home#index'
|
||||
# get '/login', to: 'sessions#new', as: :login
|
||||
# post '/login', to: 'sessions#create'
|
||||
|
@ -81,9 +81,9 @@ module Lotus
|
|||
# logout GET, HEAD /logout Sessions::Destroy
|
||||
#
|
||||
# @example Custom formatter
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# router = Lotus::Router.new do
|
||||
# router = Hanami::Router.new do
|
||||
# get '/', to: 'home#index'
|
||||
# get '/login', to: 'sessions#new', as: :login
|
||||
# post '/login', to: 'sessions#create'
|
||||
|
@ -101,24 +101,24 @@ module Lotus
|
|||
# | GET, HEAD | logout | /logout | Sessions::Destroy |
|
||||
#
|
||||
# @example Nested routes
|
||||
# require 'lotus/router'
|
||||
# require 'hanami/router'
|
||||
#
|
||||
# class AdminLotusApp
|
||||
# class AdminHanamiApp
|
||||
# def call(env)
|
||||
# end
|
||||
# def routes
|
||||
# Lotus::Router.new {
|
||||
# Hanami::Router.new {
|
||||
# get '/home', to: 'home#index'
|
||||
# }
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# router = Lotus::Router.new {
|
||||
# router = Hanami::Router.new {
|
||||
# get '/fakeroute', to: 'fake#index'
|
||||
# mount AdminLotusApp, at: '/admin'
|
||||
# mount Lotus::Router.new {
|
||||
# mount AdminHanamiApp, at: '/admin'
|
||||
# mount Hanami::Router.new {
|
||||
# get '/posts', to: 'posts#index'
|
||||
# mount Lotus::Router.new {
|
||||
# mount Hanami::Router.new {
|
||||
# get '/comments', to: 'comments#index'
|
||||
# }, at: '/second_mount'
|
||||
# }, at: '/api'
|
||||
|
@ -143,15 +143,15 @@ module Lotus
|
|||
# Returns a string representation of routes
|
||||
#
|
||||
# @param formatter [String] the template for the output
|
||||
# @param base_path [Lotus::Utils::PathPrefix] the base path
|
||||
# @param base_path [Hanami::Utils::PathPrefix] the base path
|
||||
#
|
||||
# @return [String] serialized routes from router
|
||||
#
|
||||
# @since 0.5.1
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Routing::RoutesInspector#FORMATTER
|
||||
# @see Lotus::Routing::RoutesInspector#to_s
|
||||
# @see Hanami::Routing::RoutesInspector#FORMATTER
|
||||
# @see Hanami::Routing::RoutesInspector#to_s
|
||||
def inspect_routes(formatter, base_path)
|
||||
result = ''
|
||||
|
||||
|
@ -174,16 +174,16 @@ module Lotus
|
|||
# Returns a string representation of the given route
|
||||
#
|
||||
# @param formatter [String] the template for the output
|
||||
# @param route [Lotus::Routing::Route] a route
|
||||
# @param base_path [Lotus::Utils::PathPrefix] the base path
|
||||
# @param route [Hanami::Routing::Route] a route
|
||||
# @param base_path [Hanami::Utils::PathPrefix] the base path
|
||||
#
|
||||
# @return [String] serialized route
|
||||
#
|
||||
# @since 0.2.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Routing::RoutesInspector#FORMATTER
|
||||
# @see Lotus::Routing::RoutesInspector#to_s
|
||||
# @see Hanami::Routing::RoutesInspector#FORMATTER
|
||||
# @see Hanami::Routing::RoutesInspector#to_s
|
||||
def inspect_route(formatter, route, base_path)
|
||||
formatter % Hash[
|
||||
name: route.name,
|
||||
|
@ -196,17 +196,17 @@ module Lotus
|
|||
# Returns a string representation of the given router
|
||||
#
|
||||
# @param formatter [String] the template for the output
|
||||
# @param router [Lotus::Router] a router
|
||||
# @param route [Lotus::Routing::Route] a route
|
||||
# @param base_path [Lotus::Utils::PathPrefix] the base path
|
||||
# @param router [Hanami::Router] a router
|
||||
# @param route [Hanami::Routing::Route] a route
|
||||
# @param base_path [Hanami::Utils::PathPrefix] the base path
|
||||
#
|
||||
# @return [String] serialized routes from router
|
||||
#
|
||||
# @since 0.2.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Routing::RoutesInspector#FORMATTER
|
||||
# @see Lotus::Routing::RoutesInspector#to_s
|
||||
# @see Hanami::Routing::RoutesInspector#FORMATTER
|
||||
# @see Hanami::Routing::RoutesInspector#to_s
|
||||
def inspect_router(formatter, router, route, base_path)
|
||||
router.inspector.inspect_routes(formatter, base_path.join(route.path_for_generation))
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
require 'lotus/router'
|
|
@ -1,14 +1,14 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Routing::Error do
|
||||
describe Hanami::Routing::Error do
|
||||
it 'inherits from ::StandardError' do
|
||||
Lotus::Routing::Error.superclass.must_equal StandardError
|
||||
Hanami::Routing::Error.superclass.must_equal StandardError
|
||||
end
|
||||
|
||||
it 'is parent to all custom exception' do
|
||||
Lotus::Routing::Parsing::BodyParsingError.superclass.must_equal Lotus::Routing::Error
|
||||
Lotus::Routing::Parsing::UnknownParserError.superclass.must_equal Lotus::Routing::Error
|
||||
Lotus::Routing::InvalidRouteException.superclass.must_equal Lotus::Routing::Error
|
||||
Lotus::Routing::EndpointNotFound.superclass.must_equal Lotus::Routing::Error
|
||||
Hanami::Routing::Parsing::BodyParsingError.superclass.must_equal Hanami::Routing::Error
|
||||
Hanami::Routing::Parsing::UnknownParserError.superclass.must_equal Hanami::Routing::Error
|
||||
Hanami::Routing::InvalidRouteException.superclass.must_equal Hanami::Routing::Error
|
||||
Hanami::Routing::EndpointNotFound.superclass.must_equal Hanami::Routing::Error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'rexml/document'
|
||||
require 'lotus/routing/parsing/parser'
|
||||
require 'hanami/routing/parsing/parser'
|
||||
|
||||
module Web
|
||||
module Controllers
|
||||
|
@ -374,7 +374,7 @@ module Keys
|
|||
end
|
||||
end # Keyboards
|
||||
|
||||
class XmlParser < Lotus::Routing::Parsing::Parser
|
||||
class XmlParser < Hanami::Routing::Parsing::Parser
|
||||
def mime_types
|
||||
['application/xml', 'text/xml']
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
# Bug https://github.com/lotus/router/issues/73
|
||||
describe Hanami::Router do
|
||||
# Bug https://github.com/hanami/router/issues/73
|
||||
it 'respects the Rack spec' do
|
||||
router = Lotus::Router.new(force_ssl: true)
|
||||
router = Hanami::Router.new(force_ssl: true)
|
||||
router.public_send(:get, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
|
@ -12,7 +12,7 @@ describe Lotus::Router do
|
|||
|
||||
%w{get}.each do |verb|
|
||||
it "force_ssl to true and scheme is http, return 307 and new location, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true)
|
||||
router = Hanami::Router.new(force_ssl: true)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
|
@ -24,11 +24,11 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it "force_ssl to true and scheme is https, return 200, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true, scheme: 'https', host: 'lotus.test')
|
||||
router = Hanami::Router.new(force_ssl: true, scheme: 'https', host: 'hanami.test')
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
status, headers, body = app.public_send(verb, 'https://lotus.test/http_destination', lint: true)
|
||||
status, headers, body = app.public_send(verb, 'https://hanami.test/http_destination', lint: true)
|
||||
|
||||
status.must_equal 200
|
||||
headers['Location'].must_be_nil
|
||||
|
@ -38,7 +38,7 @@ describe Lotus::Router do
|
|||
|
||||
%w{post put patch delete options}.each do |verb|
|
||||
it "force_ssl to true and scheme is http, return 307 and new location, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true)
|
||||
router = Hanami::Router.new(force_ssl: true)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
||||
|
@ -50,7 +50,7 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it "force_ssl to true and added query string, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true)
|
||||
router = Hanami::Router.new(force_ssl: true)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
@ -63,7 +63,7 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it "force_ssl to true and added port, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true, port: 4000)
|
||||
router = Hanami::Router.new(force_ssl: true, port: 4000)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
@ -76,7 +76,7 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it "force_ssl to true, added host and port, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: true, host: 'lotusrb.org', port: 4000)
|
||||
router = Hanami::Router.new(force_ssl: true, host: 'hanamirb.org', port: 4000)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
@ -84,12 +84,12 @@ describe Lotus::Router do
|
|||
status, headers, body = app.public_send(verb, '/http_destination?foo=bar', lint: true)
|
||||
|
||||
status.must_equal 307
|
||||
headers['Location'].must_equal 'https://lotusrb.org:4000/http_destination?foo=bar'
|
||||
headers['Location'].must_equal 'https://hanamirb.org:4000/http_destination?foo=bar'
|
||||
body.body.must_equal ''
|
||||
end
|
||||
|
||||
it "force_ssl to false and scheme is http, return 200 and doesn't return new location, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: false)
|
||||
router = Hanami::Router.new(force_ssl: false)
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
@ -102,7 +102,7 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it "force_ssl to false and scheme is https, return 200 and doesn't return new location, verb: #{verb}" do
|
||||
router = Lotus::Router.new(force_ssl: false, scheme: 'https')
|
||||
router = Hanami::Router.new(force_ssl: false, scheme: 'https')
|
||||
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe 'generation' do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@test = GenerationTestCase.new(@router)
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ describe 'Body parsing' do
|
|||
[200, {}, [env['router.params'].inspect]]
|
||||
}
|
||||
|
||||
@routes = Lotus::Router.new(parsers: [:json, XmlParser.new]) {
|
||||
@routes = Hanami::Router.new(parsers: [:json, XmlParser.new]) {
|
||||
patch '/books/:id', to: endpoint
|
||||
patch '/authors/:id', to: endpoint
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new { get '/', to: ->(env) {} }
|
||||
@router = Hanami::Router.new { get '/', to: ->(env) {} }
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe 'Lotus::Controller integration' do
|
||||
describe 'Hanami::Controller integration' do
|
||||
before do
|
||||
@routes = Lotus::Router.new do
|
||||
@routes = Hanami::Router.new do
|
||||
get '/payments', to: CreditCards::Index
|
||||
get '/ccs', to: 'credit_cards#index'
|
||||
resources :credit_cards, only: [:index]
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe 'Lotus integration' do
|
||||
describe 'Hanami integration' do
|
||||
before do
|
||||
@router_container = Lotus::Router.new(scheme: 'https', host: 'lotus.test', port: 443) do
|
||||
@router_container = Hanami::Router.new(scheme: 'https', host: 'hanami.test', port: 443) do
|
||||
mount Dashboard::Index, at: '/dashboard'
|
||||
mount Backend::App, at: '/backend'
|
||||
end
|
||||
|
||||
@routes = Lotus::Router.new(namespace: Travels::Controllers) do
|
||||
@routes = Hanami::Router.new(namespace: Travels::Controllers) do
|
||||
get '/dashboard', to: 'journeys#index'
|
||||
resources :journeys, only: [:index]
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe 'Lotus middleware integration' do
|
||||
describe 'Hanami middleware integration' do
|
||||
before do
|
||||
@routes = Lotus::Router.new(namespace: Web::Controllers) do
|
||||
@routes = Hanami::Router.new(namespace: Web::Controllers) do
|
||||
get '/', to: 'home#index'
|
||||
get '/dashboard', to: 'dashboard#index'
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'test_helper'
|
|||
|
||||
describe 'Nested resources' do
|
||||
before do
|
||||
@router = Lotus::Router.new(namespace: Nested::Controllers) do
|
||||
@router = Hanami::Router.new(namespace: Nested::Controllers) do
|
||||
resources :users do
|
||||
resources :posts
|
||||
resource :avatar
|
||||
|
@ -255,7 +255,7 @@ describe 'Nested resources' do
|
|||
|
||||
describe 'overriding controller without namespace' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
resources :users do
|
||||
resources :posts do
|
||||
resources :comments, controller: 'posts'
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'test_helper'
|
|||
|
||||
describe 'Pass on response' do
|
||||
before do
|
||||
@routes = Lotus::Router.new { get '/', to: ->(env) { Rack::Response.new } }
|
||||
@routes = Hanami::Router.new { get '/', to: ->(env) { Rack::Response.new } }
|
||||
@app = Rack::MockRequest.new(@routes)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'test_helper'
|
|||
|
||||
describe 'Router wrapper as container' do
|
||||
it 'reach correct application' do
|
||||
@router_container = Lotus::Router.new(scheme: 'https', host: 'lotus.test', port: 443) do
|
||||
@router_container = Hanami::Router.new(scheme: 'https', host: 'hanami.test', port: 443) do
|
||||
mount Front::App, at: '/front'
|
||||
mount Back::App, at: '/back'
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe 'usage with Rack::ShowExceptions' do
|
||||
before do
|
||||
router = Lotus::Router.new { get '/', to: 'missing#index' }
|
||||
router = Hanami::Router.new { get '/', to: 'missing#index' }
|
||||
builder = Rack::Builder.new
|
||||
builder.use Rack::ShowExceptions
|
||||
builder.run router
|
||||
|
@ -15,7 +15,7 @@ describe Lotus::Router do
|
|||
response = @app.get('/', lint: true)
|
||||
|
||||
response.status.must_equal 500
|
||||
response.body.must_match 'Lotus::Routing::EndpointNotFound'
|
||||
response.body.must_match 'Hanami::Routing::EndpointNotFound'
|
||||
end
|
||||
|
||||
it 'shows exceptions page (when requesting HTML)' do
|
||||
|
@ -23,7 +23,7 @@ describe Lotus::Router do
|
|||
|
||||
response.status.must_equal 500
|
||||
response.body.must_match '<body>'
|
||||
response.body.must_match 'Lotus::Routing::EndpointNotFound'
|
||||
response.body.must_match 'Hanami::Routing::EndpointNotFound'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
mount Api::App, at: '/api'
|
||||
mount Api::App.new, at: '/api2'
|
||||
mount Backend::App, at: '/backend'
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new(scheme: 'https', host: 'test.com', port: 443)
|
||||
@router = Hanami::Router.new(scheme: 'https', host: 'test.com', port: 443)
|
||||
|
||||
@router.get('/lotus', to: endpoint, as: :fixed)
|
||||
@router.get('/hanami', to: endpoint, as: :fixed)
|
||||
@router.get('/flowers/:id', to: endpoint, as: :variables)
|
||||
@router.get('/books/:id', id: /\d+/, to: endpoint, as: :constraints)
|
||||
@router.get('/articles(.:format)', to: endpoint, as: :optional)
|
||||
|
@ -19,17 +19,17 @@ describe Lotus::Router do
|
|||
|
||||
describe '#path' do
|
||||
it 'recognizes fixed string' do
|
||||
@router.path(:fixed).must_equal '/lotus'
|
||||
@router.path(:fixed).must_equal '/hanami'
|
||||
end
|
||||
|
||||
it 'recognizes string with variables' do
|
||||
@router.path(:variables, id: 'lotus').must_equal '/flowers/lotus'
|
||||
@router.path(:variables, id: 'hanami').must_equal '/flowers/hanami'
|
||||
end
|
||||
|
||||
it "raises error when variables aren't satisfied" do
|
||||
exception = -> {
|
||||
@router.path(:variables)
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (path) could be generated for :variables - please check given arguments'
|
||||
end
|
||||
|
@ -41,7 +41,7 @@ describe Lotus::Router do
|
|||
it "raises error when constraints aren't satisfied" do
|
||||
exception = -> {
|
||||
@router.path(:constraints, id: 'x')
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (path) could be generated for :constraints - please check given arguments'
|
||||
end
|
||||
|
@ -58,13 +58,13 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it 'escapes additional params in query string' do
|
||||
@router.path(:fixed, return_to: '/dashboard').must_equal '/lotus?return_to=%2Fdashboard'
|
||||
@router.path(:fixed, return_to: '/dashboard').must_equal '/hanami?return_to=%2Fdashboard'
|
||||
end
|
||||
|
||||
it 'raises error when insufficient params are passed' do
|
||||
exception = -> {
|
||||
@router.path(nil)
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (path) could be generated for nil - please check given arguments'
|
||||
end
|
||||
|
@ -72,7 +72,7 @@ describe Lotus::Router do
|
|||
it 'raises error when too many params are passed' do
|
||||
exception = -> {
|
||||
@router.path(:fixed, 'x')
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'HttpRouter::TooManyParametersException - please check given arguments'
|
||||
end
|
||||
|
@ -80,17 +80,17 @@ describe Lotus::Router do
|
|||
|
||||
describe '#url' do
|
||||
it 'recognizes fixed string' do
|
||||
@router.url(:fixed).must_equal 'https://test.com/lotus'
|
||||
@router.url(:fixed).must_equal 'https://test.com/hanami'
|
||||
end
|
||||
|
||||
it 'recognizes string with variables' do
|
||||
@router.url(:variables, id: 'lotus').must_equal 'https://test.com/flowers/lotus'
|
||||
@router.url(:variables, id: 'hanami').must_equal 'https://test.com/flowers/hanami'
|
||||
end
|
||||
|
||||
it "raises error when variables aren't satisfied" do
|
||||
exception = -> {
|
||||
@router.url(:variables)
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (url) could be generated for :variables - please check given arguments'
|
||||
end
|
||||
|
@ -102,7 +102,7 @@ describe Lotus::Router do
|
|||
it "raises error when constraints aren't satisfied" do
|
||||
exception = -> {
|
||||
@router.url(:constraints, id: 'x')
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (url) could be generated for :constraints - please check given arguments'
|
||||
end
|
||||
|
@ -119,13 +119,13 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it 'escapes additional params in query string' do
|
||||
@router.url(:fixed, return_to: '/dashboard').must_equal 'https://test.com/lotus?return_to=%2Fdashboard'
|
||||
@router.url(:fixed, return_to: '/dashboard').must_equal 'https://test.com/hanami?return_to=%2Fdashboard'
|
||||
end
|
||||
|
||||
it 'raises error when insufficient params are passed' do
|
||||
exception = -> {
|
||||
@router.url(nil)
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'No route (url) could be generated for nil - please check given arguments'
|
||||
end
|
||||
|
@ -133,7 +133,7 @@ describe Lotus::Router do
|
|||
it 'raises error when too many params are passed' do
|
||||
exception = -> {
|
||||
@router.url(:fixed, 'x')
|
||||
}.must_raise(Lotus::Routing::InvalidRouteException)
|
||||
}.must_raise(Hanami::Routing::InvalidRouteException)
|
||||
|
||||
exception.message.must_equal 'HttpRouter::TooManyParametersException - please check given arguments'
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
@ -181,7 +181,7 @@ describe Lotus::Router do
|
|||
@app.request('PATCH', '/electronics/keyboards/23', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/electronics/keyboards/23', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_electronics_keyboards) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_electronics_keyboards) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_electronics_keyboards - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
@ -209,7 +209,7 @@ describe Lotus::Router do
|
|||
@app.request('PATCH', '/electronics/keyboards/23', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/electronics/keyboards/23', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_electronics_keyboards) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_electronics_keyboards) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_electronics_keyboards - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
@ -294,7 +294,7 @@ describe Lotus::Router do
|
|||
@app.request('POST', '/settings/profile', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/settings/profile', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_settings_profile) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_settings_profile) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_settings_profile - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
@ -323,7 +323,7 @@ describe Lotus::Router do
|
|||
it 'does not recognize other paths' do
|
||||
@app.request('GET', '/settings/profile/edit', lint: true).status.must_equal 404
|
||||
|
||||
exception = -> { @router.path(:edit_settings_profile) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:edit_settings_profile) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :edit_settings_profile - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe '.new' do
|
||||
before do
|
||||
class MockRoute
|
||||
end
|
||||
|
||||
endpoint = ->(env) { [200, {}, ['']] }
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/route', to: endpoint
|
||||
get '/named_route', to: endpoint, as: :named_route
|
||||
resource 'avatar'
|
||||
|
@ -20,14 +20,14 @@ describe Lotus::Router do
|
|||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
it 'returns instance of Lotus::Router with empty block' do
|
||||
router = Lotus::Router.new { }
|
||||
router.must_be_instance_of Lotus::Router
|
||||
it 'returns instance of Hanami::Router with empty block' do
|
||||
router = Hanami::Router.new { }
|
||||
router.must_be_instance_of Hanami::Router
|
||||
end
|
||||
|
||||
it 'evaluates routes passed from Lotus::Router.define' do
|
||||
routes = Lotus::Router.define { post '/domains', to: ->(env) {[201, {}, ['Domain Created']]} }
|
||||
router = Lotus::Router.new(&routes)
|
||||
it 'evaluates routes passed from Hanami::Router.define' do
|
||||
routes = Hanami::Router.define { post '/domains', to: ->(env) {[201, {}, ['Domain Created']]} }
|
||||
router = Hanami::Router.new(&routes)
|
||||
|
||||
app = Rack::MockRequest.new(router)
|
||||
response = app.post('/domains', lint: true)
|
||||
|
@ -36,12 +36,12 @@ describe Lotus::Router do
|
|||
response.body.must_equal 'Domain Created'
|
||||
end
|
||||
|
||||
it 'returns instance of Lotus::Router' do
|
||||
@router.must_be_instance_of Lotus::Router
|
||||
it 'returns instance of Hanami::Router' do
|
||||
@router.must_be_instance_of Hanami::Router
|
||||
end
|
||||
|
||||
it 'sets options' do
|
||||
router = Lotus::Router.new(scheme: 'https') do
|
||||
router = Hanami::Router.new(scheme: 'https') do
|
||||
get '/', to: ->(env) { }, as: :root
|
||||
end
|
||||
|
||||
|
@ -49,17 +49,17 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it 'sets custom separator' do
|
||||
router = Lotus::Router.new(action_separator: '^')
|
||||
router = Hanami::Router.new(action_separator: '^')
|
||||
route = router.get('/', to: 'test^show', as: :root)
|
||||
|
||||
route.dest.must_equal(Test::Show)
|
||||
end
|
||||
|
||||
it 'checks if there are defined routes' do
|
||||
router = Lotus::Router.new
|
||||
router = Hanami::Router.new
|
||||
router.wont_be :defined?
|
||||
|
||||
router = Lotus::Router.new { get '/', to: ->(env) { } }
|
||||
router = Hanami::Router.new { get '/', to: ->(env) { } }
|
||||
router.must_be :defined?
|
||||
end
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ module Prefix
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe 'with prefix option' do
|
||||
before do
|
||||
@router = Lotus::Router.new(scheme: 'https', host: 'lotus.test', port: 443, prefix: '/admin', namespace: Prefix::Controllers) do
|
||||
@router = Hanami::Router.new(scheme: 'https', host: 'hanami.test', port: 443, prefix: '/admin', namespace: Prefix::Controllers) do
|
||||
get '/home', to: 'home#index', as: :get_home
|
||||
post '/home', to: 'home#index', as: :post_home
|
||||
put '/home', to: 'home#index', as: :put_home
|
||||
|
@ -84,25 +84,25 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it 'generates absolute URLs with prefix' do
|
||||
@router.url(:get_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:post_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:put_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:patch_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:delete_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:trace_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:options_home).must_equal 'https://lotus.test/admin/home'
|
||||
@router.url(:get_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:post_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:put_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:patch_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:delete_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:trace_home).must_equal 'https://hanami.test/admin/home'
|
||||
@router.url(:options_home).must_equal 'https://hanami.test/admin/home'
|
||||
|
||||
@router.url(:users).must_equal 'https://lotus.test/admin/users'
|
||||
@router.url(:new_user).must_equal 'https://lotus.test/admin/users/new'
|
||||
@router.url(:users).must_equal 'https://lotus.test/admin/users'
|
||||
@router.url(:user, id: 1).must_equal 'https://lotus.test/admin/users/1'
|
||||
@router.url(:edit_user, id: 1).must_equal 'https://lotus.test/admin/users/1/edit'
|
||||
@router.url(:users).must_equal 'https://hanami.test/admin/users'
|
||||
@router.url(:new_user).must_equal 'https://hanami.test/admin/users/new'
|
||||
@router.url(:users).must_equal 'https://hanami.test/admin/users'
|
||||
@router.url(:user, id: 1).must_equal 'https://hanami.test/admin/users/1'
|
||||
@router.url(:edit_user, id: 1).must_equal 'https://hanami.test/admin/users/1/edit'
|
||||
|
||||
@router.url(:new_asteroid).must_equal 'https://lotus.test/admin/asteroid/new'
|
||||
@router.url(:asteroid).must_equal 'https://lotus.test/admin/asteroid'
|
||||
@router.url(:edit_asteroid).must_equal 'https://lotus.test/admin/asteroid/edit'
|
||||
@router.url(:new_asteroid).must_equal 'https://hanami.test/admin/asteroid/new'
|
||||
@router.url(:asteroid).must_equal 'https://hanami.test/admin/asteroid'
|
||||
@router.url(:edit_asteroid).must_equal 'https://hanami.test/admin/asteroid/edit'
|
||||
|
||||
@router.url(:dashboard_home).must_equal 'https://lotus.test/admin/dashboard/home'
|
||||
@router.url(:dashboard_home).must_equal 'https://hanami.test/admin/dashboard/home'
|
||||
end
|
||||
|
||||
%w(GET POST PUT PATCH DELETE TRACE OPTIONS).each do |verb|
|
||||
|
@ -132,7 +132,7 @@ describe Lotus::Router do
|
|||
end
|
||||
|
||||
it 'redirect works with prefix' do
|
||||
router = Lotus::Router.new(prefix: '/admin') do
|
||||
router = Hanami::Router.new(prefix: '/admin') do
|
||||
redirect '/redirect', to: '/redirect_destination'
|
||||
get '/redirect_destination', to: ->(env) { [200, {}, ['Redirect destination!']] }
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe 'recognition' do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@test = RecognitionTestCase.new(@router)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe '#recognize' do
|
||||
before do
|
||||
@router = Lotus::Router.new(namespace: Web::Controllers) do
|
||||
@router = Hanami::Router.new(namespace: Web::Controllers) do
|
||||
get '/', to: 'home#index', as: :home
|
||||
get '/dashboard', to: Web::Controllers::Dashboard::Index, as: :dashboard
|
||||
get '/rack_class', to: RackMiddleware, as: :rack_class
|
||||
|
@ -96,7 +96,7 @@ describe Lotus::Router do
|
|||
env = Rack::MockRequest.env_for('/', method: :post)
|
||||
route = @router.recognize(env)
|
||||
|
||||
exception = -> { route.call(env) }.must_raise Lotus::Router::NotRoutableEndpointError
|
||||
exception = -> { route.call(env) }.must_raise Hanami::Router::NotRoutableEndpointError
|
||||
exception.message.must_equal 'Cannot find routable endpoint for POST "/"'
|
||||
end
|
||||
end
|
||||
|
@ -177,7 +177,7 @@ describe Lotus::Router do
|
|||
env = Rack::MockRequest.env_for('/', method: :post)
|
||||
route = @router.recognize('/', method: :post)
|
||||
|
||||
exception = -> { route.call(env) }.must_raise Lotus::Router::NotRoutableEndpointError
|
||||
exception = -> { route.call(env) }.must_raise Hanami::Router::NotRoutableEndpointError
|
||||
exception.message.must_equal 'Cannot find routable endpoint for POST "/"'
|
||||
end
|
||||
end
|
||||
|
@ -264,7 +264,7 @@ describe Lotus::Router do
|
|||
env = Rack::MockRequest.env_for('/', method: :post)
|
||||
route = @router.recognize(:home, {method: :post}, {})
|
||||
|
||||
exception = -> { route.call(env) }.must_raise Lotus::Router::NotRoutableEndpointError
|
||||
exception = -> { route.call(env) }.must_raise Hanami::Router::NotRoutableEndpointError
|
||||
exception.message.must_equal 'Cannot find routable endpoint for POST "/"'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
end
|
||||
|
||||
describe '#redirect' do
|
||||
|
|
|
@ -5,8 +5,8 @@ describe 'SCRIPT_NAME' do
|
|||
include Rack::Test::Methods
|
||||
|
||||
before do
|
||||
@container = Lotus::Router.new do
|
||||
mount Lotus::Router.new(prefix: '/admin') {
|
||||
@container = Hanami::Router.new do
|
||||
mount Hanami::Router.new(prefix: '/admin') {
|
||||
get '/foo', to: ->(env) { [200, {}, [::Rack::Request.new(env).url]] }
|
||||
}, at: '/admin'
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ describe Lotus::Router do
|
|||
@app.request('GET', '/profile', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/profile', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_profile) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_profile) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_profile - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
@ -88,7 +88,7 @@ describe Lotus::Router do
|
|||
@app.request('GET', '/profile', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/profile', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_profile) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_profile) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_profile - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
@ -70,7 +70,7 @@ describe Lotus::Router do
|
|||
@app.request('PATCH', '/keyboards/23', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/keyboards/23', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_keyboards) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_keyboards) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_keyboards - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ describe Lotus::Router do
|
|||
@app.request('PATCH', '/keyboards/23', lint: true).status.must_equal 405
|
||||
@app.request('DELETE', '/keyboards/23', lint: true).status.must_equal 405
|
||||
|
||||
exception = -> { @router.path(:new_keyboards) }.must_raise Lotus::Routing::InvalidRouteException
|
||||
exception = -> { @router.path(:new_keyboards) }.must_raise Hanami::Routing::InvalidRouteException
|
||||
exception.message.must_equal 'No route (path) could be generated for :new_keyboards - please check given arguments'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
describe '.define' do
|
||||
it 'returns block as it is' do
|
||||
routes = -> { get '/', to: ->(env) {[200, {}, ['OK']]} }
|
||||
Lotus::Router.define(&routes).must_equal routes
|
||||
Hanami::Router.define(&routes).must_equal routes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Routing::EndpointResolver do
|
||||
describe Hanami::Routing::EndpointResolver do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new
|
||||
@resolver = Hanami::Routing::EndpointResolver.new
|
||||
end
|
||||
|
||||
it 'recognizes :to when it is a callable object' do
|
||||
|
@ -32,7 +32,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
options = { to: 'missing_endpoint' }
|
||||
endpoint = @resolver.resolve(options)
|
||||
|
||||
-> { endpoint.call({}) }.must_raise Lotus::Routing::EndpointNotFound
|
||||
-> { endpoint.call({}) }.must_raise Hanami::Routing::EndpointNotFound
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,7 +48,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
|
||||
describe 'namespace' do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(namespace: TestApp)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(namespace: TestApp)
|
||||
end
|
||||
|
||||
it 'recognizes :to when it is a string and an explicit namespace' do
|
||||
|
@ -64,17 +64,17 @@ describe Lotus::Routing::EndpointResolver do
|
|||
|
||||
describe 'endpoint' do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(namespace: Web::Controllers)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(namespace: Web::Controllers)
|
||||
end
|
||||
|
||||
it 'if :to is an action without middleware' do
|
||||
options = { to: 'dashboard#index' }
|
||||
@resolver.resolve(options).class.must_equal Lotus::Routing::ClassEndpoint
|
||||
@resolver.resolve(options).class.must_equal Hanami::Routing::ClassEndpoint
|
||||
end
|
||||
|
||||
it 'if :to is an action with middleware' do
|
||||
options = { to: 'home#index' }
|
||||
@resolver.resolve(options).class.must_equal Lotus::Routing::Endpoint
|
||||
@resolver.resolve(options).class.must_equal Hanami::Routing::Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,7 +85,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
end
|
||||
|
||||
def routes
|
||||
Lotus::Router.new do
|
||||
Hanami::Router.new do
|
||||
get '/home', to: 'home#index'
|
||||
end
|
||||
end
|
||||
|
@ -109,7 +109,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
end
|
||||
end
|
||||
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(endpoint: CustomEndpoint)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(endpoint: CustomEndpoint)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -123,7 +123,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
|
||||
describe 'custom separator' do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(action_separator: action_separator)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(action_separator: action_separator)
|
||||
end
|
||||
|
||||
let(:action_separator) { '@' }
|
||||
|
@ -136,7 +136,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
|
||||
describe 'custom suffix' do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(suffix: suffix)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(suffix: suffix)
|
||||
end
|
||||
|
||||
let(:suffix) { 'Controller::' }
|
||||
|
@ -149,7 +149,7 @@ describe Lotus::Routing::EndpointResolver do
|
|||
|
||||
describe 'custom pattern' do
|
||||
before do
|
||||
@resolver = Lotus::Routing::EndpointResolver.new(pattern: pattern)
|
||||
@resolver = Hanami::Routing::EndpointResolver.new(pattern: pattern)
|
||||
end
|
||||
|
||||
let(:pattern) { 'Controllers::%{controller}::%{action}' }
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require 'test_helper'
|
||||
require 'rack/mock'
|
||||
|
||||
describe Lotus::Routing::Parsers do
|
||||
describe Hanami::Routing::Parsers do
|
||||
describe '#initialize' do
|
||||
it 'raises error when unknown parser is given' do
|
||||
begin
|
||||
Lotus::Routing::Parsers.new(:a_parser)
|
||||
rescue Lotus::Routing::Parsing::UnknownParserError => e
|
||||
Hanami::Routing::Parsers.new(:a_parser)
|
||||
rescue Hanami::Routing::Parsing::UnknownParserError => e
|
||||
e.message.must_equal "Unknown Parser: `a_parser'"
|
||||
end
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ describe Lotus::Routing::Parsers do
|
|||
|
||||
describe '#call' do
|
||||
before do
|
||||
@parsers = Lotus::Routing::Parsers.new(parsers)
|
||||
@parsers = Hanami::Routing::Parsers.new(parsers)
|
||||
end
|
||||
|
||||
let(:env) { Rack::MockRequest.env_for('/', method: 'POST', 'CONTENT_TYPE' => content_type, input: body) }
|
||||
|
@ -50,9 +50,9 @@ describe Lotus::Routing::Parsers do
|
|||
end
|
||||
|
||||
describe 'with malformed json' do
|
||||
let(:body) { %({"lotus":"ok" "attribute":"ok"}) }
|
||||
let(:body) { %({"hanami":"ok" "attribute":"ok"}) }
|
||||
it 'raises an exception' do
|
||||
-> { result = @parsers.call(env) }.must_raise(Lotus::Routing::Parsing::BodyParsingError)
|
||||
-> { result = @parsers.call(env) }.must_raise(Hanami::Routing::Parsing::BodyParsingError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -67,9 +67,9 @@ describe Lotus::Routing::Parsers do
|
|||
end
|
||||
|
||||
describe 'with malformed json' do
|
||||
let(:body) { %({"lotus":"ok" "attribute":"ok"}) }
|
||||
let(:body) { %({"hanami":"ok" "attribute":"ok"}) }
|
||||
it 'raises an exception' do
|
||||
-> { result = @parsers.call(env) }.must_raise(Lotus::Routing::Parsing::BodyParsingError)
|
||||
-> { result = @parsers.call(env) }.must_raise(Hanami::Routing::Parsing::BodyParsingError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Routing::Resource::Options do
|
||||
describe Hanami::Routing::Resource::Options do
|
||||
before do
|
||||
@actions = [:index, :new, :create, :show, :edit, :update, :destroy]
|
||||
end
|
||||
|
||||
it 'returns all the actions when no exceptions are requested' do
|
||||
Lotus::Routing::Resources::Options.new(@actions).actions.must_equal @actions
|
||||
Hanami::Routing::Resources::Options.new(@actions).actions.must_equal @actions
|
||||
end
|
||||
|
||||
it 'returns only the action requested via the :only option' do
|
||||
options = Lotus::Routing::Resources::Options.new(@actions, only: :show)
|
||||
options = Hanami::Routing::Resources::Options.new(@actions, only: :show)
|
||||
options.actions.must_equal [:show]
|
||||
end
|
||||
|
||||
it 'returns only the actions requested via the :only options' do
|
||||
options = Lotus::Routing::Resources::Options.new(@actions, only: [:create, :edit])
|
||||
options = Hanami::Routing::Resources::Options.new(@actions, only: [:create, :edit])
|
||||
options.actions.must_equal [:create, :edit]
|
||||
end
|
||||
|
||||
it 'returns only the action not rejected via the :except option' do
|
||||
options = Lotus::Routing::Resources::Options.new(@actions, except: :destroy)
|
||||
options = Hanami::Routing::Resources::Options.new(@actions, except: :destroy)
|
||||
options.actions.must_equal [:index, :new, :create, :show, :edit, :update]
|
||||
end
|
||||
|
||||
it 'returns only the actions requested via the :only options' do
|
||||
options = Lotus::Routing::Resources::Options.new(@actions, except: [:index, :new, :edit])
|
||||
options = Hanami::Routing::Resources::Options.new(@actions, except: [:index, :new, :edit])
|
||||
options.actions.must_equal [:create, :show, :update, :destroy]
|
||||
end
|
||||
|
||||
it 'allow access to values' do
|
||||
options = Lotus::Routing::Resources::Options.new(@actions, name: :lotus)
|
||||
options[:name].must_equal :lotus
|
||||
options = Hanami::Routing::Resources::Options.new(@actions, name: :hanami)
|
||||
options[:name].must_equal :hanami
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/routing/routes_inspector'
|
||||
require 'hanami/routing/routes_inspector'
|
||||
|
||||
describe Lotus::Routing::RoutesInspector do
|
||||
describe Hanami::Routing::RoutesInspector do
|
||||
describe '#to_s' do
|
||||
before do
|
||||
@path = ::File.expand_path(__FILE__)
|
||||
|
@ -9,7 +9,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'named routes with procs' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/login', to: ->(env) { }, as: :login
|
||||
get '/logout', to: Proc.new {|env| }, as: :logout
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'controller action syntax' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/controller/action', to: 'welcome#index'
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'lazy controller and action' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/lazy', to: 'sleepy#index'
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'missing controller and action' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/missing', to: 'missing#index'
|
||||
end
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'class' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/class', to: RackMiddleware
|
||||
end
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'object' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/class', to: RackMiddlewareInstanceMethod
|
||||
get '/object', to: RackMiddlewareInstanceMethod.new
|
||||
end
|
||||
|
@ -136,7 +136,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'resource' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
resource 'identity'
|
||||
end
|
||||
end
|
||||
|
@ -160,7 +160,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'resources' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
resources 'books'
|
||||
end
|
||||
end
|
||||
|
@ -185,7 +185,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'with custom formatter' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/login', to: ->(env) { }, as: :login
|
||||
end
|
||||
end
|
||||
|
@ -205,28 +205,28 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'nested routes' do
|
||||
before do
|
||||
class AdminLotusApp
|
||||
class AdminHanamiApp
|
||||
def call(env)
|
||||
end
|
||||
|
||||
def routes
|
||||
Lotus::Router.new do
|
||||
Hanami::Router.new do
|
||||
get '/home', to: 'home#index'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
inner_router = Lotus::Router.new {
|
||||
inner_router = Hanami::Router.new {
|
||||
get '/comments', to: 'comments#index'
|
||||
}
|
||||
nested_router = Lotus::Router.new {
|
||||
nested_router = Hanami::Router.new {
|
||||
get '/posts', to: 'posts#index'
|
||||
mount inner_router, at: '/second_mount'
|
||||
}
|
||||
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/fakeroute', to: 'fake#index'
|
||||
mount AdminLotusApp, at: '/admin'
|
||||
mount AdminHanamiApp, at: '/admin'
|
||||
mount nested_router, at: '/api'
|
||||
mount RackMiddleware, at: '/class'
|
||||
mount RackMiddlewareInstanceMethod, at: '/instance_from_class'
|
||||
|
@ -270,7 +270,7 @@ describe Lotus::Routing::RoutesInspector do
|
|||
|
||||
describe 'with header option' do
|
||||
before do
|
||||
@router = Lotus::Router.new do
|
||||
@router = Hanami::Router.new do
|
||||
get '/controller/action', to: 'welcome#index'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router do
|
||||
describe Hanami::Router do
|
||||
before do
|
||||
@router = Lotus::Router.new
|
||||
@router = Hanami::Router.new
|
||||
@app = Rack::MockRequest.new(@router)
|
||||
end
|
||||
|
||||
|
@ -16,30 +16,30 @@ describe Lotus::Router do
|
|||
describe 'path recognition' do
|
||||
it 'recognize fixed string' do
|
||||
response = [200, {}, ['Fixed!']]
|
||||
@router.send(verb, '/lotus', to: ->(env) { response })
|
||||
@router.send(verb, '/hanami', to: ->(env) { response })
|
||||
|
||||
response.must_be_same_as @app.request(verb.upcase, '/lotus', lint: true)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/hanami', lint: true)
|
||||
end
|
||||
|
||||
it 'recognize moving parts string' do
|
||||
response = [200, {}, ['Moving!']]
|
||||
@router.send(verb, '/lotus/:id', to: ->(env) { response })
|
||||
@router.send(verb, '/hanami/:id', to: ->(env) { response })
|
||||
|
||||
response.must_be_same_as @app.request(verb.upcase, '/lotus/23', lint: true)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/hanami/23', lint: true)
|
||||
end
|
||||
|
||||
it 'recognize globbing string' do
|
||||
response = [200, {}, ['Globbing!']]
|
||||
@router.send(verb, '/lotus/*', to: ->(env) { response })
|
||||
@router.send(verb, '/hanami/*', to: ->(env) { response })
|
||||
|
||||
response.must_be_same_as @app.request(verb.upcase, '/lotus/all', lint: true)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/hanami/all', lint: true)
|
||||
end
|
||||
|
||||
it 'recognize format string' do
|
||||
response = [200, {}, ['Format!']]
|
||||
@router.send(verb, '/lotus/:id(.:format)', to: ->(env) { response })
|
||||
@router.send(verb, '/hanami/:id(.:format)', to: ->(env) { response })
|
||||
|
||||
response.must_be_same_as @app.request(verb.upcase, '/lotus/all.json', lint: true)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/hanami/all.json', lint: true)
|
||||
end
|
||||
|
||||
it 'accepts a block' do
|
||||
|
@ -72,10 +72,10 @@ describe Lotus::Router do
|
|||
it 'allows custom url parts' do
|
||||
response = [200, {}, ['Named route with custom parts!']]
|
||||
|
||||
router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org', port: 443)
|
||||
router = Hanami::Router.new(scheme: 'https', host: 'hanamirb.org', port: 443)
|
||||
router.send(verb, '/custom_named_route', to: ->(env) { response }, as: :"#{ verb }_custom_named_route")
|
||||
|
||||
router.url(:"#{ verb }_custom_named_route").must_equal 'https://lotusrb.org/custom_named_route'
|
||||
router.url(:"#{ verb }_custom_named_route").must_equal 'https://hanamirb.org/custom_named_route'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,10 +83,10 @@ describe Lotus::Router do
|
|||
it 'recognize when called with matching constraints' do
|
||||
response = [200, {}, ['Moving with constraints!']]
|
||||
|
||||
@router.send(verb, '/lotus/:id', to: ->(env) { response }, id: /\d+/)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/lotus/23', lint: true)
|
||||
@router.send(verb, '/hanami/:id', to: ->(env) { response }, id: /\d+/)
|
||||
response.must_be_same_as @app.request(verb.upcase, '/hanami/23', lint: true)
|
||||
|
||||
@app.request(verb.upcase, '/lotus/flower', lint: true).status.must_equal 404
|
||||
@app.request(verb.upcase, '/hanami/flower', lint: true).status.must_equal 404
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ require 'minitest/autorun'
|
|||
require 'support/generation_test_case'
|
||||
require 'support/recognition_test_case'
|
||||
$:.unshift 'lib'
|
||||
require 'lotus-router'
|
||||
require 'hanami-router'
|
||||
|
||||
Rack::MockResponse.class_eval do
|
||||
def equal?(other)
|
||||
|
@ -32,7 +32,7 @@ Rack::MockResponse.class_eval do
|
|||
end
|
||||
end
|
||||
|
||||
Lotus::Router.class_eval do
|
||||
Hanami::Router.class_eval do
|
||||
def reset!
|
||||
@router.reset!
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Router::VERSION do
|
||||
describe Hanami::Router::VERSION do
|
||||
it 'exposes version' do
|
||||
Lotus::Router::VERSION.must_equal '0.5.1'
|
||||
Hanami::Router::VERSION.must_equal '0.6.0'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue