Giter Site home page Giter Site logo

Comments (5)

AlfonsoUceda avatar AlfonsoUceda commented on May 9, 2024

@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.

jodosha avatar jodosha commented on May 9, 2024

@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.

AlfonsoUceda avatar AlfonsoUceda commented on May 9, 2024

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.

jodosha avatar jodosha commented on May 9, 2024

@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.

AlfonsoUceda avatar AlfonsoUceda commented on May 9, 2024

Yeah, I was thinking in implement routes accessor for Lotus::Router, thank @jodosha

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.