Class: MiddleSquid::Runner

Inherits:
Object
  • Object
show all
Includes:
Actions, Helpers
Defined in:
lib/middle_squid/runner.rb

Overview

Used internally to start the configured adapter and the internal HTTP server. The handler passed to Builder#run will be called in this context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#download_like

Methods included from Actions

#accept, #intercept, #redirect_to, #replace_by

Constructor Details

#initialize(builder) ⇒ Runner

Returns a new instance of Runner.

Raises:

  • (Error)

    if the handler is undefined



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/middle_squid/runner.rb', line 17

def initialize(builder)
  raise Error, 'Invalid handler. Did you call Builder#run in your configuration file?' unless builder.handler

  define_singleton_method :_handler_wrapper, builder.handler

  builder.custom_actions.each {|name, body|
    define_singleton_method name, body
  }

  adapter = builder.adapter
  adapter.handler = method :_handler_wrapper

  @server = Server.new

  EM.run {
    adapter.start
    @server.start
  }
end

Instance Attribute Details

#serverServer (readonly)

Returns the internal HTTP server.

Returns:



14
15
16
# File 'lib/middle_squid/runner.rb', line 14

def server
  @server
end