class Nginxtra::ConfigConverter
Public Class Methods
new(output)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 3 def initialize(output) @converted = false @output = output @indentation = Nginxtra::Config::Indentation.new end
Public Instance Methods
convert(options)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 9 def convert(options) raise Nginxtra::Error::ConvertFailed, "The convert method can only be called once!" if converted? header compile_options options[:binary_status] config_file options[:config] footer converted! end
Private Instance Methods
chomp_comment(input)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 100 def chomp_comment(input) loop do c = input.read(1) break unless c break if c == "\n" end end
compile_options(status)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 25 def compile_options(status) return unless status options = (status[/^configure arguments:\s*(.*)$/, 1] || "").strip return if options.empty? options = options.split(/\s+/) process_passenger_compile_options! options options.each do |option| next if invalid_compile_option? option @output.print @indentation @output.puts %(compile_option "#{option}") end end
config_file(input)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 58 def config_file(input) return unless input @output.print @indentation @output.puts %(file "nginx.conf" do) @indentation.increment line = Nginxtra::ConfigConverter::Line.new @indentation, @output each_token(input) do |token| line << token if line.terminated? line.puts line = Nginxtra::ConfigConverter::Line.new @indentation, @output end end raise Nginxtra::Error::ConvertFailed, "Unexpected end of file!" unless line.empty? @indentation.decrement @output.print @indentation @output.puts "end" end
converted!()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 114 def converted! @converted = true end
converted?()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 118 def converted? @converted end
each_token(input) { |instance while ready?| ... }
click to toggle source
# File lib/nginxtra/config_converter.rb, line 80 def each_token(input) token = Nginxtra::ConfigConverter::Token.new loop do c = input.read(1) break unless c if c == "#" chomp_comment input else token << c end yield token.instance while token.ready? end yield token.instance while token.ready? raise Nginxtra::Error::ConvertFailed, "Unexpected end of file in mid token!" unless token.value.empty? end
header()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 20 def header @output.puts "nginxtra.config do" @indentation.increment end
invalid_compile_option?(option)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 50 def invalid_compile_option?(option) return true if option =~ /--prefix=/ return true if option =~ /--sbin-path=/ return true if option =~ /--conf-path=/ return true if option =~ /--pid-path=/ false end
process_passenger_compile_options!(options)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 39 def process_passenger_compile_options!(options) return if options.select { |x| x =~ %r{^--add-module.*/passenger.*} }.empty? @output.print @indentation @output.puts "require_passenger!" options.delete_if do |x| next true if x =~ %r{^--add-module.*/passenger.*} ["--with-http_ssl_module", "--with-http_gzip_static_module", "--with-cc-opt=-Wno-error"].include? x end end