Comments (5)
@jodosha the idea is:
puts Lotus::Router.new {
mount Lotus::Router.new {
get '/posts', to: 'posts#index'
}, at: '/api'
}.inspector
" /api* #<Lotus::Router> "
" GET, HEAD /api/posts Posts::Index "
# =>
isn't it?
from router.
@AlfonsoUceda Exactly, and we should also fake full stack Lotus apps.
FakeLotusApp = OpenStruct.new(routes: Lotus::Router.new { ... })
puts Lotus::Router.new {
mount FakeLotusApp.new, at: '/'
}.inspector
from router.
Ok @jodosha I'm researching with this example:
require 'lotus/router'
require 'ostruct'
FakeLotusApp = OpenStruct.new(routes: Lotus::Router.new { get '/home', to: 'home#index' })
router = Lotus::Router.new {
get '/fakeroute', to: 'fake#index'
mount FakeLotusApp.new, at: '/'
mount Lotus::Router.new {
get '/posts', to: 'posts#index'
}, at: '/api'
}
router.inspector.to_s #=>
" /* #<Proc@/home/alfonso/Proyectos/lotus/forks/router/lib/lotus/routing/endpoint_resolver.rb:188 (lambda)>\n /api* #<Lotus::Router> \n"
the inspector in to_s method do a loop at every route but, the route in the loop doesn't respond to routes and to access the destination I have to do this:
router.instance_variable_get(:@router).routes.first.dest #=> Fake::Index
router.instance_variable_get(:@router).routes.first.dest.class #=> Lotus::Routing::LazyEndpoint
router.instance_variable_get(:@router).routes.first.dest.__getobj__.instance_variable_get(:@router) # ArgumentError: not delegated
router.instance_variable_get(:@router).routes[1].dest.__getobj__ #=> #<Proc:0x00000001fc9ad0@/home/alfonso/Proyectos/lotus/forks/router/lib/lotus/routing/endpoint_resolver.rb:188 (lambda)>
router.instance_variable_get(:@router).routes[1].dest.class #=> Lotus::Routing::Endpoint
router.instance_variable_get(:@router).routes[1].dest.__getobj__.instance_variable_get(:@router) #=> nil
router.instance_variable_get(:@router).routes[2].dest.__getobj__ #=> #<Lotus::Router:0x00000001fc9a80 @router= ..... >
router.instance_variable_get(:@router).routes[2].dest.class #=> Lotus::Routing::Endpoint
router.instance_variable_get(:@router).routes[2].dest.__getobj__.instance_variable_get(:@router) #=> #<HttpRouter:0xf5300c...>
I think we should go through destination class and check if it has the router. what do you think?
from router.
@AlfonsoUceda Does the trick explained in the description work?
Bookshelf::Application.new.routes # => An instance of Lotus::Router
Lotus::Router.new.routes # => To be implemented in this PR, returns self, an instance of Lotus::Router
In Inspector#to_s
def to_s(formatter = FORMATTER)
result = ""
@routes.each do |route|
result << if route.respond_to?(:routes)
# Lotus::Application subclass or Lotus::Router instance
route.routes.inspect.to_s(formatter)
else
formatter % inspect_route(route)
end
end
result
end
from router.
Yeah, I was thinking in implement routes accessor for Lotus::Router, thank @jodosha
from router.
Related Issues (20)
- BodyParser's fallback "_" key in env["router.params"] unnecessary for typical x-www-form-urlencoded bodies? HOT 2
- http_router dependency generates `warning: URI.unescape is obsolete` HOT 3
- Standalone routing with method override HOT 2
- Warning: URI.unescape is obsolete HOT 2
- Nested variables/resources HOT 2
- Fake support for Ruby 3 HOT 2
- POST route recognised as GET HOT 2
- 405 response does not include Allow header
- Surprising prefix behavior HOT 2
- Unclear errors with differently named wildcard segments HOT 5
- URL fragments and routing HOT 2
- Exception when JSON body contains % HOT 7
- Failing edge cases for optional variables
- Path segments in base_url can get clobbered by UrlHelpers
- Per-slice middleware not being applied correctly? HOT 3
- Capture names affects finding nested routes HOT 2
- Catch-all has higher priority than mount HOT 2
- Routes with multiple variables not working in common nested route scenario HOT 2
- Inconsistent trailing slash behaviour HOT 1
- Middleware usage does not work as expected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from router.