我有一个很小的 Sinatra 项目,我需要在其中覆盖Rack::Auth::Basic#valid?
. 目前我已经将此覆盖放在我的应用程序的主文件中,但是随着事情变得越来越大,这似乎使源代码变得混乱......
require "sinatra/base"
module Rack::Auth
class Basic
def valid?(auth)
# My overrides go here...
end
end
end
class App < Sinatra::Base
use Rack::Auth::Basic, "CustomRealm" do |username, password|
# Authentication
end
get "/" do
erb :index
end
end
我想将覆盖移动到外部文件。我的项目结构类似于
* views
|------ index.erb
* config.ru
* app.rb
* README.md
* LICENSE.md
* Gemfile
* Gemfile.lock
我可以在哪里移动Rack::Auth
覆盖以便我可以从内部使用它们app.rb
?我试过穿上它们,lib/rack/auth/basic.rb
但根本没有用……Sinatra 的标准是什么?