Class: H2OConfigurator::Builder
- Inherits:
-
Object
- Object
- H2OConfigurator::Builder
- Defined in:
- lib/h2o-configurator/builder.rb
Instance Method Summary collapse
- #check_config(file) ⇒ Object
-
#initialize(site_dirs = nil) ⇒ Builder
constructor
A new instance of Builder.
- #make_config ⇒ Object
- #write_config ⇒ Object
Constructor Details
#initialize(site_dirs = nil) ⇒ Builder
Returns a new instance of Builder.
5 6 7 |
# File 'lib/h2o-configurator/builder.rb', line 5 def initialize(site_dirs=nil) @site_dirs = site_dirs ? site_dirs.map { |p| Path.new(p) } : Path.glob(SitesDirGlob) end |
Instance Method Details
#check_config(file) ⇒ Object
34 35 36 37 |
# File 'lib/h2o-configurator/builder.rb', line 34 def check_config(file) system('h2o', '--mode=test', '--conf', file.to_s) raise Error, "h2o check failed: status #{$?.to_i}" unless $?.success? end |
#make_config ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/h2o-configurator/builder.rb', line 9 def make_config @site_dirs.reject! { |p| p.extname == '.old' || p.extname == '.new' } raise "No sites defined" if @site_dirs.empty? config = { 'compress' => 'ON', 'reproxy' => 'ON', 'error-log' => ErrorLogFile.to_s, 'hosts' => {}, } @site_dirs.sort.each do |dir| host = Host.new(dir) puts "%30s => %s" % [host.name, host.dir] config['hosts'].merge!(host.make_config) end config end |
#write_config ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/h2o-configurator/builder.rb', line 26 def write_config H2OConfFile.write(YAML.dump(make_config)) InstalledHandlersDir.rmtree if InstalledHandlersDir.exist? HandlersDir.cp_r(InstalledHandlersDir) H2OLogDir.mkpath check_config(H2OConfFile) end |