Module: Middleman::CoreExtensions::Request::ClassMethods
- Defined in:
- lib/middleman-core/core_extensions/request.rb
Instance Method Summary collapse
-
#app ⇒ Rack::Builder
The shared Rack instance being build.
-
#call(env) ⇒ Object
Call prototype, use in config.ru.
-
#inst(&block) ⇒ Middleman::Application
Get the static instance.
-
#inst=(inst) ⇒ void
Set the shared instance.
-
#map(map, &block) ⇒ void
Add Rack App mapped to specific path.
-
#prototype ⇒ Rack::Builder
Prototype app.
-
#reset! ⇒ Object
Reset Rack setup.
-
#to_rack_app(&block) ⇒ Rack::Builder
Return built Rack app.
-
#use(middleware, *args, &block) ⇒ void
Use Rack middleware.
Instance Method Details
#app ⇒ Rack::Builder
The shared Rack instance being build
46 47 48 |
# File 'lib/middleman-core/core_extensions/request.rb', line 46 def app @app ||= ::Rack::Builder.new end |
#call(env) ⇒ Object
Call prototype, use in config.ru
103 104 105 |
# File 'lib/middleman-core/core_extensions/request.rb', line 103 def call(env) prototype.call(env) end |
#inst(&block) ⇒ Middleman::Application
Get the static instance
54 55 56 57 58 59 60 |
# File 'lib/middleman-core/core_extensions/request.rb', line 54 def inst(&block) @inst ||= begin mm = new(&block) mm.run_hook :ready mm end end |
#inst=(inst) ⇒ void
This method returns an undefined value.
Set the shared instance
67 68 69 |
# File 'lib/middleman-core/core_extensions/request.rb', line 67 def inst=(inst) @inst = inst end |
#map(map, &block) ⇒ void
This method returns an undefined value.
Add Rack App mapped to specific path
120 121 122 123 |
# File 'lib/middleman-core/core_extensions/request.rb', line 120 def map(map, &block) @mappings ||= [] @mappings << [map, block] end |
#prototype ⇒ Rack::Builder
Prototype app. Used in config.ru
95 96 97 98 |
# File 'lib/middleman-core/core_extensions/request.rb', line 95 def prototype reset! to_rack_app end |
#reset! ⇒ Object
Reset Rack setup
38 39 40 |
# File 'lib/middleman-core/core_extensions/request.rb', line 38 def reset! @app = nil end |
#to_rack_app(&block) ⇒ Rack::Builder
Return built Rack app
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/middleman-core/core_extensions/request.rb', line 75 def to_rack_app(&block) inner_app = inst(&block) (@middleware || []).each do |m| app.use(m[0], *m[1], &m[2]) end app.map("/") { run inner_app } (@mappings || []).each do |m| app.map(m[0], &m[1]) end app end |
#use(middleware, *args, &block) ⇒ void
This method returns an undefined value.
Use Rack middleware
111 112 113 114 |
# File 'lib/middleman-core/core_extensions/request.rb', line 111 def use(middleware, *args, &block) @middleware ||= [] @middleware << [middleware, args, block] end |