Class: HAProxy::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/haproxy/parser.rb

Overview

Responsible for reading an HAProxy config file and building an HAProxy::Config instance.

Constant Summary collapse

Error =

Raised when an error occurs during parsing.

Class.new(StandardError)
SERVER_ATTRIBUTE_NAMES_1_3 =

haproxy 1.3

%w{
  addr backup check cookie disabled fall id inter fastinter downinter
  maxconn maxqueue minconn port redir rise slowstart source track weight
}
SERVER_ATTRIBUTE_NAMES_1_4 =

Added in haproxy 1.4

%w{error-limit observe on-error}
SERVER_ATTRIBUTE_NAMES =
SERVER_ATTRIBUTE_NAMES_1_3 + SERVER_ATTRIBUTE_NAMES_1_4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Parser

Returns a new instance of Parser.



18
19
20
21
22
23
24
# File 'lib/haproxy/parser.rb', line 18

def initialize(options = nil)
  options ||= {}
  options = { :verbose => false }.merge(options)

  self.options = options
  self.verbose = options[:verbose]
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/haproxy/parser.rb', line 16

def options
  @options
end

#parse_resultObject

Returns the value of attribute parse_result.



16
17
18
# File 'lib/haproxy/parser.rb', line 16

def parse_result
  @parse_result
end

#verboseObject

Returns the value of attribute verbose.



16
17
18
# File 'lib/haproxy/parser.rb', line 16

def verbose
  @verbose
end

Instance Method Details

#parse(config_text) ⇒ Object



31
32
33
34
35
# File 'lib/haproxy/parser.rb', line 31

def parse(config_text)
  result = parse_config_text(config_text)
  self.parse_result = result
  build_config(result)
end

#parse_file(filename) ⇒ Object



26
27
28
29
# File 'lib/haproxy/parser.rb', line 26

def parse_file(filename)
  config_text = File.read(filename)
  self.parse(config_text)
end