class Sanford::ServerData

Attributes

debug[R]
dtcp_logger[R]
error_procs[R]
ip[RW]

The server uses this to “compile” the common configuration data used by the server instances, error handlers and routes. The goal here is to provide these with a simplified interface with the minimal data needed and to decouple the configuration from each thing that needs its data.

logger[R]
name[R]
num_workers[R]
pid_file[R]
port[RW]

The server uses this to “compile” the common configuration data used by the server instances, error handlers and routes. The goal here is to provide these with a simplified interface with the minimal data needed and to decouple the configuration from each thing that needs its data.

process_label[R]
receives_keep_alive[R]
router[R]
routes[R]
shutdown_timeout[R]
template_source[R]
verbose_logging[R]
worker_class[R]
worker_params[R]

Public Class Methods

new(args = nil) click to toggle source
# File lib/sanford/server_data.rb, line 17
def initialize(args = nil)
  args ||= {}
  @name     = args[:name]
  @ip       = !(v = ENV['SANFORD_IP'].to_s).empty?   ? v      : args[:ip]
  @port     = !(v = ENV['SANFORD_PORT'].to_s).empty? ? v.to_i : args[:port]
  @pid_file = args[:pid_file]

  @shutdown_timeout = args[:shutdown_timeout]

  @worker_class    = args[:worker_class]
  @worker_params   = args[:worker_params] || {}
  @num_workers     = args[:num_workers]
  @error_procs     = args[:error_procs] || []
  @template_source = args[:template_source]
  @logger          = args[:logger]
  @router          = args[:router]

  @receives_keep_alive = !!args[:receives_keep_alive]
  @verbose_logging     = !!args[:verbose_logging]

  @debug       = !ENV['SANFORD_DEBUG'].to_s.empty?
  @dtcp_logger = @logger if @debug
  @routes      = build_routes(args[:routes] || [])

  @process_label = if (label = ENV['SANFORD_PROCESS_LABEL'].to_s).empty?
    "#{@name}-#{@ip}-#{@port}"
  else
    label
  end
end

Public Instance Methods

route_for(name) click to toggle source
# File lib/sanford/server_data.rb, line 48
def route_for(name)
  @routes[name] || raise(NotFoundError, "no service named '#{name}'")
end

Private Instance Methods

build_routes(routes) click to toggle source
# File lib/sanford/server_data.rb, line 54
def build_routes(routes)
  routes.inject({}){ |h, route| h.merge(route.name => route) }
end