class Sanford::Server::Config

Constants

DEFAULT_IP_ADDRESS
DEFAULT_NUM_WORKERS

Attributes

error_procs[RW]
init_procs[RW]
ip[RW]
logger[RW]
name[RW]
num_workers[RW]
pid_file[RW]
port[RW]
receives_keep_alive[RW]
router[RW]
shutdown_timeout[RW]
template_source[RW]
verbose_logging[RW]
worker_class[RW]
worker_params[RW]

Public Class Methods

new() click to toggle source
# File lib/sanford/server.rb, line 262
def initialize
  @name             = nil
  @ip               = DEFAULT_IP_ADDRESS
  @port             = nil
  @pid_file         = nil
  @shutdown_timeout = nil
  @worker_class     = DefaultWorker
  @worker_params    = nil
  @num_workers      = DEFAULT_NUM_WORKERS
  @init_procs       = []
  @error_procs      = []
  @template_source  = Sanford::NullTemplateSource.new(ENV['PWD'])
  @logger           = Sanford::NullLogger.new
  @router           = Sanford::Router.new

  @receives_keep_alive = false
  @verbose_logging     = true

  @valid = nil
end

Public Instance Methods

routes() click to toggle source
# File lib/sanford/server.rb, line 283
def routes
  self.router.routes
end
valid?() click to toggle source
# File lib/sanford/server.rb, line 287
def valid?
  !!@valid
end
validate!() click to toggle source

for the config to be considered “valid”, a few things need to happen. The key here is that this only needs to be done once for each config.

# File lib/sanford/server.rb, line 294
def validate!
  return @valid if !@valid.nil? # only need to run this once per config

  # ensure all user and plugin configs/settings are applied
  self.init_procs.each(&:call)
  [:name, :ip, :port].each do |a|
    if self.send(a).nil?
      raise InvalidError, "a name, ip and port must be configured"
    end
  end

  # validate the worker class
  if !self.worker_class.kind_of?(Class) || !self.worker_class.include?(Sanford::Worker)
    raise InvalidError, "worker class must include `#{Sanford::Worker}`"
  end

  # validate the router
  self.router.validate!

  @valid = true # if it made it this far, it's valid!
end