chrysalis-router
chrysalis-router
Chrysalis router is a simple router that just "finds route, gives you something you attached to it". It can be anything with the type provided. String, Int, block, whatewer you want.
Router was created to work only with paths(urls). No methods, no middleware. Search - not found - exception. Found - you get an attachment.
Installation
Add this to your application's shard.yml
:
dependencies:
chrysalis-router:
github: idchlife/chrysalis-router
Usage
require "chrysalis-router"
include Chrysalis::Router
# First, create an instance of manager with your type. Your type exactly
# would be the returned attachment, if route found.
manager = RoutesManager(YourType).new
# Add route with attachment to it
manager.add_route "/fleeb", YourType
# You can also add types with :variables
# This route will be found with "/fleeb/56/plumbus" or "/fleeb/juice/plumbus"
manager.add_route "/fleeb/:id/plumbus", YourType
# Then get attachment when you got path. Mind rescuing exception! Router
# raises an exception if no route found! It was made like this so you can
# make that nil can be also an attachment
begin
attachment : YourType = manager.resolve_path "/fleeb"
rescue RouteNotFoundException
raise "Whoops 404 guys"
end
# You can also debug structure of tree of routes by doing this
puts manager.debug_tree_structure
Note: trailing slashes are not seekable. Only paths without them will be found
Development
Issues, tests and ideas are welcome! Keep in mind - this router is made to be simple part of something larger.
Contributing
- Fork it ( https://github.com/idchlife/chrysalis-router/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- idchlife idchlife - creator, maintainer
Repository
chrysalis-router
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- over 7 years ago
- March 2, 2017
License
MIT License
Links
Synced at
Fri, 22 Nov 2024 02:49:45 GMT
Languages