Class: Alf::Rack::Connect
- Inherits:
-
Object
- Object
- Alf::Rack::Connect
- Defined in:
- lib/alf/rack/connect.rb
Overview
Connect to a database and make the connection available in the Rack environment.
Example:
“‘ require ’sinatra’
use Alf::Rack::Connect do |cfg| # see Alf::Rack::Config
cfg.database = ... # (required) a Alf::Database or Alf::Adapter
end
get ‘/’ do
# the configuration object (a dup of what has been seen above)
config = env[Alf::Rack::Connect::CONFIG_KEY]
# the config object is connected
connection = config.connection
# => Alf::Database::Connection
# ...
end “‘
Constant Summary collapse
- CONFIG_KEY =
"ALF_RACK_CONFIG".freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config = Config.new) {|config| ... } ⇒ Connect
constructor
A new instance of Connect.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/alf/rack/connect.rb', line 36 def call(env) env[CONFIG_KEY] = cfg = @config.dup cfg.connect do @app.call(env) end end |