Class: Sanford::ServerData

Inherits:
Object
  • Object
show all
Defined in:
lib/sanford/server_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ ServerData

Returns a new instance of ServerData.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Attribute Details

#debugObject (readonly)

Returns the value of attribute debug.



15
16
17
# File 'lib/sanford/server_data.rb', line 15

def debug
  @debug
end

#dtcp_loggerObject (readonly)

Returns the value of attribute dtcp_logger.



15
16
17
# File 'lib/sanford/server_data.rb', line 15

def dtcp_logger
  @dtcp_logger
end

#error_procsObject (readonly)

Returns the value of attribute error_procs.



13
14
15
# File 'lib/sanford/server_data.rb', line 13

def error_procs
  @error_procs
end

#ipObject

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.



10
11
12
# File 'lib/sanford/server_data.rb', line 10

def ip
  @ip
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/sanford/server_data.rb', line 13

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/sanford/server_data.rb', line 11

def name
  @name
end

#num_workersObject (readonly)

Returns the value of attribute num_workers.



12
13
14
# File 'lib/sanford/server_data.rb', line 12

def num_workers
  @num_workers
end

#pid_fileObject (readonly)

Returns the value of attribute pid_file.



11
12
13
# File 'lib/sanford/server_data.rb', line 11

def pid_file
  @pid_file
end

#portObject

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.



10
11
12
# File 'lib/sanford/server_data.rb', line 10

def port
  @port
end

#process_labelObject (readonly)

Returns the value of attribute process_label.



15
16
17
# File 'lib/sanford/server_data.rb', line 15

def process_label
  @process_label
end

#receives_keep_aliveObject (readonly)

Returns the value of attribute receives_keep_alive.



14
15
16
# File 'lib/sanford/server_data.rb', line 14

def receives_keep_alive
  @receives_keep_alive
end

#routerObject (readonly)

Returns the value of attribute router.



13
14
15
# File 'lib/sanford/server_data.rb', line 13

def router
  @router
end

#routesObject (readonly)

Returns the value of attribute routes.



15
16
17
# File 'lib/sanford/server_data.rb', line 15

def routes
  @routes
end

#shutdown_timeoutObject (readonly)

Returns the value of attribute shutdown_timeout.



11
12
13
# File 'lib/sanford/server_data.rb', line 11

def shutdown_timeout
  @shutdown_timeout
end

#template_sourceObject (readonly)

Returns the value of attribute template_source.



13
14
15
# File 'lib/sanford/server_data.rb', line 13

def template_source
  @template_source
end

#verbose_loggingObject (readonly)

Returns the value of attribute verbose_logging.



14
15
16
# File 'lib/sanford/server_data.rb', line 14

def verbose_logging
  @verbose_logging
end

#worker_classObject (readonly)

Returns the value of attribute worker_class.



12
13
14
# File 'lib/sanford/server_data.rb', line 12

def worker_class
  @worker_class
end

#worker_paramsObject (readonly)

Returns the value of attribute worker_params.



12
13
14
# File 'lib/sanford/server_data.rb', line 12

def worker_params
  @worker_params
end

Instance Method Details

#route_for(name) ⇒ Object



48
49
50
# File 'lib/sanford/server_data.rb', line 48

def route_for(name)
  @routes[name] || raise(NotFoundError, "no service named '#{name}'")
end