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

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

Instance Method Summary (collapse)

Instance Method Details

- (Rack::Builder) app

The shared Rack instance being build

Returns:

  • (Rack::Builder)


45
46
47
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 45

def app
  @app ||= ::Rack::Builder.new
end

- (Object) call(env)

Call prototype, use in config.ru



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

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

- (Middleman::Application) inst(&block)

Get the static instance



53
54
55
56
57
58
59
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 53

def inst(&block)
  @inst ||= begin
    mm = new(&block)
    mm.run_hook :ready
    mm
  end
end

- (void) inst=(inst)

This method returns an undefined value.

Set the shared instance

Parameters:



66
67
68
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 66

def inst=(inst)
  @inst = inst
end

- (void) map(map, &block)

This method returns an undefined value.

Add Rack App mapped to specific path

Parameters:

  • map (String)

    Path to map



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

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

- (Rack::Builder) prototype

Prototype app. Used in config.ru

Returns:

  • (Rack::Builder)


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

def prototype
  @prototype ||= to_rack_app
end

- (Object) reset!

Reset Rack setup



36
37
38
39
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 36

def reset!
  @app = nil
  @prototype = nil
end

- (Rack::Builder) to_rack_app(&block)

Return built Rack app

Returns:

  • (Rack::Builder)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'middleman-core/lib/middleman-core/core_extensions/request.rb', line 74

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

- (void) use(middleware, *args, &block)

This method returns an undefined value.

Use Rack middleware

Parameters:

  • middleware (Class)

    Middleware module



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

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