Class: NginxConfig
- Inherits:
-
Object
- Object
- NginxConfig
- Defined in:
- lib/utils/nginx_parser.rb
Class Method Summary collapse
Class Method Details
.parse(content) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/utils/nginx_parser.rb', line 87 def self.parse(content) lex = NginxParser.new.parse(content) tree = NginxTransform.new.apply(lex) gtree = NginxTransform::Group.new(nil, '', tree) read_nginx_group(gtree) rescue Parslet::ParseFailed => err raise "Failed to parse NginX config: #{err}" end |
.read_nginx_group(t) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/utils/nginx_parser.rb', line 96 def self.read_nginx_group(t) agg_conf = Hash.new([]) agg_conf['_'] = t.args unless t.args == '' groups, conf = t.body.partition { |i| i.is_a? NginxTransform::Group } conf.each { |x| agg_conf[x.key] += [x.vals] } groups.each { |x| agg_conf[x.id] += [read_nginx_group(x)] } agg_conf end |