Class: NginxConfigParser::Section

Inherits:
Configuration show all
Defined in:
lib/nginx_config_parser/configuration.rb

Overview

A Section of settings

Instance Attribute Summary collapse

Attributes inherited from Configuration

#settings

Instance Method Summary collapse

Methods inherited from Configuration

#[]=, #each, #section, #sections

Constructor Details

#initialize(level, name, value = nil) ⇒ Section

Returns a new instance of Section.



49
50
51
52
53
# File 'lib/nginx_config_parser/configuration.rb', line 49

def initialize(level, name, value=nil)
  @name = name
  @value = value
  super(level)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'lib/nginx_config_parser/configuration.rb', line 48

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



48
49
50
# File 'lib/nginx_config_parser/configuration.rb', line 48

def value
  @value
end

Instance Method Details

#to_sObject

:nodoc:



55
56
57
58
59
60
61
62
63
64
# File 'lib/nginx_config_parser/configuration.rb', line 55

def to_s #:nodoc:
  lines = []
  lines << (('  ' * (@level - 1)) << [@name, Array(@value)].flatten.compact.map { |v| v.to_s }.join(' ') << ' {')
  @settings.each do |key, value|
    lines << (('  ' * @level) << [key, Array(value)].flatten.join(' ') << ';')
  end
  lines.push(*sections.map { |section| section.to_s})
  lines << (('  ' * (@level - 1)) << '}')
  lines.join("\n")
end