class MyApacheConf

Attributes

conf[R]
to_h[R]

Public Class Methods

new(raw_s, debug: false) click to toggle source
# File lib/myapacheconf.rb, line 13
  def initialize(raw_s, debug: false)

    @debug = debug

    contents = RXFHelper.read(raw_s).first
    puts 'content: ' + contents.inspect if @debug

    s = if contents =~ /^<\?ph / then
      contents
    else
'<?ph schema="sections[title,tags]/section[x]"?>
title: Apache Config
tags: apache    

' + contents

    end

    puts ('s: ' + s.inspect).debug if @debug
    ph = PolyrexHeadings.new(s, debug: debug) 
    
    @to_h = @h = ph.to_h.first.last
    puts @to_h.inspect

    @sip = []
    @extensions = []
    build()

  end

Public Instance Methods

generate_files(dir='/tmp/') click to toggle source
# File lib/myapacheconf.rb, line 43
def generate_files(dir='/tmp/')
  
  @conf.each_pair do |domain, conf|

    puts 'domain: ' + domain.inspect if @debug
    File.write File.join(dir, ("%s.conf" % domain)), conf

  end    
end

Private Instance Methods

build() click to toggle source
# File lib/myapacheconf.rb, line 56
  def build()

    @conf = @h[:proxypassthru][:'port 80'].map do |line|

      host, addr = line.split(/ +/,2)

s = "<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyPass / http://#{addr}/
  ProxyPassReverse / http://#{addr}/
  ServerName #{host}
</VirtualHost>"

    [host, s]

    end.to_h    

  end