class Nginxtra::ConfigConverter::Line
Public Class Methods
new(indentation, output)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 224 def initialize(indentation, output) @indentation = indentation @output = output @tokens = [] end
Public Instance Methods
<<(token)
click to toggle source
# File lib/nginxtra/config_converter.rb, line 230 def <<(token) @tokens << token end
empty?()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 234 def empty? @tokens.empty? end
puts()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 242 def puts if @tokens.last.end? puts_line elsif @tokens.last.block_start? puts_block_start elsif @tokens.last.block_end? puts_block_end else raise Nginxtra::Error::ConvertFailed, "Can't puts invalid line!" end end
terminated?()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 238 def terminated? @tokens.last.terminal_character? end
Private Instance Methods
if?()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 256 def if? @tokens.first.if? end
indent()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 328 def indent @indentation.increment end
passenger?()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 260 def passenger? %w(passenger_root passenger_ruby passenger_enabled).include? @tokens.first.value end
print_args()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 311 def print_args args = @tokens[1..-2] return if args.empty? @output.print " " if if? args.first.if_start! args.last.if_end! end @output.print args.map(&:to_s).join(", ") end
print_first()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 307 def print_first @output.print @tokens.first.to_line_start end
print_indentation()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 303 def print_indentation @output.print @indentation.to_s end
print_newline(value = "")
click to toggle source
# File lib/nginxtra/config_converter.rb, line 324 def print_newline(value = "") @output.puts value end
puts_block_end()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 296 def puts_block_end raise Nginxtra::Error::ConvertFailed, "Block end can't have labels!" unless @tokens.length == 1 unindent print_indentation print_newline("end") end
puts_block_start()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 287 def puts_block_start raise Nginxtra::Error::ConvertFailed, "Block start must have a first label!" unless @tokens.length > 1 print_indentation print_first print_args print_newline(" do") indent end
puts_line()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 264 def puts_line raise Nginxtra::Error::ConvertFailed, "Line must have a first label!" unless @tokens.length > 1 return puts_passenger if passenger? print_indentation print_first print_args print_newline end
puts_passenger()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 273 def puts_passenger print_indentation if @tokens.first.value == "passenger_root" print_newline "passenger_root!" elsif @tokens.first.value == "passenger_ruby" print_newline "passenger_ruby!" elsif @tokens.first.value == "passenger_enabled" print_newline "passenger_on!" else raise Nginxtra::Error::ConvertFailed, "Whoops!" end end
unindent()
click to toggle source
# File lib/nginxtra/config_converter.rb, line 332 def unindent @indentation.decrement end