Class: Sanford::Server::Config
- Inherits:
-
Object
- Object
- Sanford::Server::Config
- Defined in:
- lib/sanford/server.rb
Constant Summary collapse
- DEFAULT_NUM_WORKERS =
4.freeze
- DEFAULT_IP_ADDRESS =
'0.0.0.0'.freeze
Instance Attribute Summary collapse
-
#error_procs ⇒ Object
Returns the value of attribute error_procs.
-
#init_procs ⇒ Object
Returns the value of attribute init_procs.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_workers ⇒ Object
Returns the value of attribute num_workers.
-
#pid_file ⇒ Object
Returns the value of attribute pid_file.
-
#port ⇒ Object
Returns the value of attribute port.
-
#receives_keep_alive ⇒ Object
Returns the value of attribute receives_keep_alive.
-
#router ⇒ Object
Returns the value of attribute router.
-
#shutdown_timeout ⇒ Object
Returns the value of attribute shutdown_timeout.
-
#template_source ⇒ Object
Returns the value of attribute template_source.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
-
#worker_class ⇒ Object
Returns the value of attribute worker_class.
-
#worker_params ⇒ Object
Returns the value of attribute worker_params.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #routes ⇒ Object
- #valid? ⇒ Boolean
-
#validate! ⇒ Object
for the config to be considered “valid”, a few things need to happen.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# 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 |
Instance Attribute Details
#error_procs ⇒ Object
Returns the value of attribute error_procs.
259 260 261 |
# File 'lib/sanford/server.rb', line 259 def error_procs @error_procs end |
#init_procs ⇒ Object
Returns the value of attribute init_procs.
259 260 261 |
# File 'lib/sanford/server.rb', line 259 def init_procs @init_procs end |
#ip ⇒ Object
Returns the value of attribute ip.
257 258 259 |
# File 'lib/sanford/server.rb', line 257 def ip @ip end |
#logger ⇒ Object
Returns the value of attribute logger.
259 260 261 |
# File 'lib/sanford/server.rb', line 259 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
257 258 259 |
# File 'lib/sanford/server.rb', line 257 def name @name end |
#num_workers ⇒ Object
Returns the value of attribute num_workers.
258 259 260 |
# File 'lib/sanford/server.rb', line 258 def num_workers @num_workers end |
#pid_file ⇒ Object
Returns the value of attribute pid_file.
257 258 259 |
# File 'lib/sanford/server.rb', line 257 def pid_file @pid_file end |
#port ⇒ Object
Returns the value of attribute port.
257 258 259 |
# File 'lib/sanford/server.rb', line 257 def port @port end |
#receives_keep_alive ⇒ Object
Returns the value of attribute receives_keep_alive.
260 261 262 |
# File 'lib/sanford/server.rb', line 260 def receives_keep_alive @receives_keep_alive end |
#router ⇒ Object
Returns the value of attribute router.
259 260 261 |
# File 'lib/sanford/server.rb', line 259 def router @router end |
#shutdown_timeout ⇒ Object
Returns the value of attribute shutdown_timeout.
257 258 259 |
# File 'lib/sanford/server.rb', line 257 def shutdown_timeout @shutdown_timeout end |
#template_source ⇒ Object
Returns the value of attribute template_source.
259 260 261 |
# File 'lib/sanford/server.rb', line 259 def template_source @template_source end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
260 261 262 |
# File 'lib/sanford/server.rb', line 260 def verbose_logging @verbose_logging end |
#worker_class ⇒ Object
Returns the value of attribute worker_class.
258 259 260 |
# File 'lib/sanford/server.rb', line 258 def worker_class @worker_class end |
#worker_params ⇒ Object
Returns the value of attribute worker_params.
258 259 260 |
# File 'lib/sanford/server.rb', line 258 def worker_params @worker_params end |
Instance Method Details
#routes ⇒ Object
283 284 285 |
# File 'lib/sanford/server.rb', line 283 def routes self.router.routes end |
#valid? ⇒ Boolean
287 288 289 |
# File 'lib/sanford/server.rb', line 287 def valid? !!@valid end |
#validate! ⇒ Object
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.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# 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 |