Class: NginxConfigParser::Configuration
- Inherits:
-
Object
- Object
- NginxConfigParser::Configuration
- Includes:
- Enumerable
- Defined in:
- lib/nginx_config_parser/configuration.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Add a setting.
- #each(&block) ⇒ Object
-
#initialize(level = 0) ⇒ Configuration
constructor
A new instance of Configuration.
-
#section(name, value) ⇒ Object
Add a child section.
-
#sections ⇒ Object
An array of child sections.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(level = 0) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 |
# File 'lib/nginx_config_parser/configuration.rb', line 8 def initialize(level=0) @level = level @settings = {} end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
7 8 9 |
# File 'lib/nginx_config_parser/configuration.rb', line 7 def settings @settings end |
Instance Method Details
#[]=(key, value) ⇒ Object
Add a setting
14 15 16 |
# File 'lib/nginx_config_parser/configuration.rb', line 14 def []=(key, value) @settings[key] = value end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/nginx_config_parser/configuration.rb', line 30 def each(&block) sections.each(&block) end |
#section(name, value) ⇒ Object
Add a child section
24 25 26 27 28 |
# File 'lib/nginx_config_parser/configuration.rb', line 24 def section(name, value) section = Section.new(@level + 1, name, value) sections << section section end |
#sections ⇒ Object
An array of child sections
19 20 21 |
# File 'lib/nginx_config_parser/configuration.rb', line 19 def sections @sections ||= [] end |
#to_s ⇒ Object
:nodoc:
34 35 36 37 38 39 40 |
# File 'lib/nginx_config_parser/configuration.rb', line 34 def to_s #:nodoc: lines = @settings.map do |key, value| (' ' * @level) << [key, Array(value)].flatten.compact.join(' ') << ';' end lines.push(*sections.map { |section| section.to_s}) lines.join("\n") end |