Class: GlTail::YamlParser
- Inherits:
-
Object
- Object
- GlTail::YamlParser
- Defined in:
- lib/gl_tail/config/yaml_parser.rb
Instance Attribute Summary collapse
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #add_blocks(column, hash) ⇒ Object
- #apply(config) ⇒ Object
- #apply_value(target, key, value) ⇒ Object
- #apply_values(target, hash) ⇒ Object
-
#initialize(file) ⇒ YamlParser
constructor
A new instance of YamlParser.
- #parse_config ⇒ Object
- #parse_resolver ⇒ Object
- #parse_servers ⇒ Object
Constructor Details
#initialize(file) ⇒ YamlParser
Returns a new instance of YamlParser.
7 8 9 10 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 7 def initialize file file ||= "config.yaml" @yaml = YAML.load_file(file) end |
Instance Attribute Details
#yaml ⇒ Object (readonly)
Returns the value of attribute yaml.
5 6 7 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 5 def yaml @yaml end |
Instance Method Details
#add_blocks(column, hash) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 85 def add_blocks(column, hash) hash.each do |key, config| block = @config.add_block(key) block.column = column apply_values(block, config) end end |
#apply(config) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 12 def apply(config) @config = config @left = Hash.new @right = Hash.new @blocks = Array.new parse_servers parse_config parse_resolver @config end |
#apply_value(target, key, value) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 54 def apply_value(target, key, value) begin target.send("#{key}=", value) rescue puts "FAILED TO APPLY #{key}=#{value} TO #{target}" raise end end |
#apply_values(target, hash) ⇒ Object
48 49 50 51 52 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 48 def apply_values(target, hash) hash.each do |key, value| apply_value(target, key, value) end end |
#parse_config ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gl_tail/config/yaml_parser.rb', line 63 def parse_config self.yaml['config'].each do |key, config| screen = @config.screen case config when Hash if key =~ /(left|right)_column/ column = screen.send($1) blocks = config.delete('blocks') apply_values(column, config) add_blocks(column, blocks) else target = screen.send(key) apply_values(target, config) end else apply_value(screen, key, config) end end end |