Class: Kongfigure::Parser
- Inherits:
-
Object
- Object
- Kongfigure::Parser
- Defined in:
- lib/kongfigure/parser.rb
Instance Method Summary collapse
-
#initialize(file, debug = false) ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
Constructor Details
#initialize(file, debug = false) ⇒ Parser
Returns a new instance of Parser.
4 5 6 7 |
# File 'lib/kongfigure/parser.rb', line 4 def initialize(file, debug=false) @yaml_erb_configuration = File.read(file) @debug = debug end |
Instance Method Details
#parse! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kongfigure/parser.rb', line 9 def parse! return @configuration unless @configuration.nil? @configuration = Kongfigure::Configuration.new puts "Parsing YAML configuration...".colorize(:color => :white, :background => :red) parsed_configuration = YAML.load(ERB.new(@yaml_erb_configuration).result) ap parsed_configuration if @debug parsed_configuration.each do |key, value| case key when "url" @configuration.url = parse_url(value) when "urls" @configuration.url = parse_url(value) when "services" @configuration.add_services(value || []) when "consumers" @configuration.add_consumers(value || []) when "plugins" @configuration.add_plugins(value || []) when "upstreams" @configuration.add_upstreams(value || []) else raise "Invalid configuration key: #{key}." end end @configuration end |