Class: HaproxyParser::FormatChecker
- Inherits:
-
Object
- Object
- HaproxyParser::FormatChecker
- Defined in:
- lib/haproxy_parser/format_checker.rb
Constant Summary collapse
- FormatError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(path) ⇒ FormatChecker
constructor
A new instance of FormatChecker.
- #lines ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(path) ⇒ FormatChecker
Returns a new instance of FormatChecker.
9 10 11 |
# File 'lib/haproxy_parser/format_checker.rb', line 9 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/haproxy_parser/format_checker.rb', line 8 def path @path end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/haproxy_parser/format_checker.rb', line 7 def result @result end |
Instance Method Details
#check ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/haproxy_parser/format_checker.rb', line 29 def check # create file whose user, group is deleted. # tmp_file = Tempfile.open("haproxy_parser") do |tmp_f| lines.each do |line| tmp_f.print(line) end tmp_f end status,_,stderr = systemu "haproxy -c -f #{tmp_file.path}" tmp_file.unlink @result = stderr unless status.success? end |
#lines ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/haproxy_parser/format_checker.rb', line 18 def lines @lines ||= [].tap do |arr| File.open(path, "r") do |f| f.each_line do |line| next if /\s+(user|group)\s+/ =~ line arr << line end end end end |
#run ⇒ Object
13 14 15 16 |
# File 'lib/haproxy_parser/format_checker.rb', line 13 def run check raise(FormatError, result) if result end |