Understanding ruby gem rack config.ru
1. test_rack_use.rb from here
# rename to config.ru
## mv test_rack_use.rb config.ru
# run app
## rackup
class Middleware
def initialize(app)
puts "in initializee"
@app = app
end
def call(env)
puts "in call"
env["rack.some_header"] = "setting an example"
@app.call(env)
end
end
puts "before Middleware"
use Middleware
puts "after Middleware"
run lambda { |env| [200, {"content-type" => "text/plain"}, ["OK"]]}
2. The meaning of lambda
lambda
is ruby module kernel method, you can find doc from ruby-lang doc.
3. The meaning of use
and run
use
and run
is Rack::Builder
method, they’re implemented as DSL, you can find the code from here and here.
Tips
Github automatically enable code navigation can show and link definitions of a named entity corresponding to a reference to that entity.
You can find doc from github doc.
Troubleshooting code navigation
If code navigation is enabled for you but you don’t see links to the definitions of functions and methods:
- Code navigation only works for active branches. Push to the branch and try again.
- Code navigation only works for repositories with fewer than 100,000 files.
- Some language not supported.