Module: Middleman::CoreExtensions::Request::ClassMethods

Defined in:
lib/middleman-core/core_extensions/request.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

Call prototype, use in config.ru



100
101
102
# File 'lib/middleman-core/core_extensions/request.rb', line 100

def call(env)
  prototype.call(env)
end

#inst(&block) ⇒ Middleman::Application

Get the static instance



47
48
49
50
51
52
53
# File 'lib/middleman-core/core_extensions/request.rb', line 47

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

Parameters:



60
61
62
# File 'lib/middleman-core/core_extensions/request.rb', line 60

def inst=(inst)
  @inst = inst
end

#map(map, &block) ⇒ void

This method returns an undefined value.

Add Rack App mapped to specific path

Parameters:

  • map (String)

    Path to map



117
118
119
120
# File 'lib/middleman-core/core_extensions/request.rb', line 117

def map(map, &block)
  @mappings ||= []
  @mappings << [map, block]
end

#prototypeRack::Builder

Prototype app. Used in config.ru

Returns:

  • (Rack::Builder)


92
93
94
95
# File 'lib/middleman-core/core_extensions/request.rb', line 92

def prototype
  reset!
  to_rack_app
end

#reset!Object

Reset Rack setup



39
40
41
# File 'lib/middleman-core/core_extensions/request.rb', line 39

def reset!
  @rack_app = nil
end

#to_rack_app(&block) ⇒ Rack::Builder

Return built Rack app

Returns:

  • (Rack::Builder)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/middleman-core/core_extensions/request.rb', line 68

def to_rack_app(&block)
  @rack_app ||= begin
    app = ::Rack::Builder.new
    app.use Rack::Lint

    Array(@middleware).each do |klass, options, block|
      app.use(klass, *options, &block)
    end

    inner_app = inst(&block)
    app.map("/") { run inner_app }

    Array(@mappings).each do |path, block|
      app.map(path, &block)
    end

    app
  end
end

#use(middleware, *args, &block) ⇒ void

This method returns an undefined value.

Use Rack middleware

Parameters:

  • middleware (Class)

    Middleware module



108
109
110
111
# File 'lib/middleman-core/core_extensions/request.rb', line 108

def use(middleware, *args, &block)
  @middleware ||= []
  @middleware << [middleware, args, block]
end