Class: Jobim::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/jobim/server.rb

Overview

HTTP Server container. Contains the Rack application definition and routing tables. Class explicitly leverages ‘::Thin::Server` to create the HTTP server, this should possibly be changed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) {|_self| ... } ⇒ Server

Returns a new instance of Server.

Yields:

  • (_self)

Yield Parameters:

  • _self (Jobim::Server)

    the object that the method was called on



19
20
21
22
23
# File 'lib/jobim/server.rb', line 19

def initialize(settings, &block)
  @settings = settings

  yield self if block_given?
end

Instance Attribute Details

#appRack::Builder

Memoized accessor for the server Rack application.

NB. This has been split into a memoized called to ‘#build_app` becuase of the way the `Rack::Builder` class handles scope in the context of `instance_eval` instead of `yield`.

Returns:

  • (Rack::Builder)


32
33
34
# File 'lib/jobim/server.rb', line 32

def app
  @app
end

#serverThin::Server

Memoized accessor for the internal server instance.

This is currently explicitly a ‘::Thin::Server`, possibly should change into a more generic form.

Returns:

  • (Thin::Server)


42
43
44
# File 'lib/jobim/server.rb', line 42

def server
  @server
end

#settingsObject

Returns the value of attribute settings.



17
18
19
# File 'lib/jobim/server.rb', line 17

def settings
  @settings
end

Class Method Details

.start!(opts) ⇒ Jobim::Server

Utitly wrapper to create and start a new ‘Jobim::Server` instnace.

Parameters:

  • opts (Hash)

    option hash for server configuration

Returns:



13
14
15
# File 'lib/jobim/server.rb', line 13

def self.start!(opts)
  Jobim::Server.new(opts).start
end

Instance Method Details

#startObject

Pass through delegation to the internal server object’s start method. Handles daemonizing the server before starting it if nessesary.



60
61
62
63
64
65
66
67
# File 'lib/jobim/server.rb', line 60

def start
  Thin::Logging.silent = settings.quiet

  puts ">>> Serving #{settings.dir}"

  server.daemonize if settings.daemonize
  server.start
end