Class: Waitress::Configure
- Inherits:
-
Object
- Object
- Waitress::Configure
- Defined in:
- lib/waitress/configure.rb
Overview
The Configure Class is used to load Waitress configurations from the filesystem, usually used in the config.rb file.
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
-
#servers ⇒ Object
Returns the value of attribute servers.
Class Method Summary collapse
- .config_target(o) ⇒ Object
-
.configure!(*args, &block) ⇒ Object
Endpoint for Waitress.configure!.
Instance Method Summary collapse
-
#generate_configs ⇒ Object
Generate the configuration file if it doesn’t already exist.
-
#initialize(root) ⇒ Configure
constructor
A new instance of Configure.
-
#join ⇒ Object
Join all the server threads in this configuration.
-
#load_cfg ⇒ Object
Load the config.rb file.
-
#read_configure(*args, &block) ⇒ Object
Read the configuration object.
-
#run ⇒ Object
Run all servers in this configuration.
Constructor Details
#initialize(root) ⇒ Configure
Returns a new instance of Configure.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/waitress/configure.rb', line 20 def initialize root @root = root @configurations = [] generate_configs load_cfg @servers = @configurations.map do |conf| s = Waitress::HttpServer.new conf.hosts.each { |h| s << h } s.set_processes conf.processes s.ports *conf.ports s.internal_error conf.internal_error s end puts "Waitress Configuration Complete" puts "Servers Started on Ports: " @servers.each do |x| puts "\t#{x.ports.join ", "}" end end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
18 19 20 |
# File 'lib/waitress/configure.rb', line 18 def root @root end |
#servers ⇒ Object
Returns the value of attribute servers.
17 18 19 |
# File 'lib/waitress/configure.rb', line 17 def servers @servers end |
Class Method Details
.config_target(o) ⇒ Object
13 14 15 |
# File 'lib/waitress/configure.rb', line 13 def self.config_target o @@configure_target = o end |
.configure!(*args, &block) ⇒ Object
Endpoint for Waitress.configure!
8 9 10 11 |
# File 'lib/waitress/configure.rb', line 8 def self.configure! *args, &block raise "Using 'configure!' outside of file target" if @@configure_target.nil? @@configure_target.read_configure *args, &block end |
Instance Method Details
#generate_configs ⇒ Object
Generate the configuration file if it doesn’t already exist.
60 61 62 63 64 65 66 67 68 |
# File 'lib/waitress/configure.rb', line 60 def generate_configs FileUtils.mkdir_p(@root) unless File.exist?(@root) raise "File #{@root} is not a directory!" unless File.directory?(@root) @config = File.join(@root, "config.rb") unless File.exist?(@config) c = File.read(File.join(Waitress::Chef.resources, "default_config.rb")) File.write(@config, c) end end |
#join ⇒ Object
Join all the server threads in this configuration
48 49 50 |
# File 'lib/waitress/configure.rb', line 48 def join @servers.each { |s| s.join } end |
#load_cfg ⇒ Object
Load the config.rb file
71 72 73 74 75 76 |
# File 'lib/waitress/configure.rb', line 71 def load_cfg Waitress::Configure.config_target self path = File.absolute_path(@config) require path Waitress::Configure.config_target nil end |
#read_configure(*args, &block) ⇒ Object
Read the configuration object
53 54 55 56 57 |
# File 'lib/waitress/configure.rb', line 53 def read_configure *args, &block config = Configuration.new self, *args block.call(config) @configurations << config end |
#run ⇒ Object
Run all servers in this configuration
43 44 45 |
# File 'lib/waitress/configure.rb', line 43 def run @servers.each { |s| s.run } end |