Class: HAProxy::Renderer
- Inherits:
-
Object
- Object
- HAProxy::Renderer
- Defined in:
- lib/haproxy/renderer.rb
Overview
Responsible for rendering an HAProxy::Config instance to a string.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#source_tree ⇒ Object
Returns the value of attribute source_tree.
Instance Method Summary collapse
-
#initialize(config, source_tree) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #render_node(node) ⇒ Object
Constructor Details
#initialize(config, source_tree) ⇒ Renderer
Returns a new instance of Renderer.
8 9 10 11 12 13 14 15 16 |
# File 'lib/haproxy/renderer.rb', line 8 def initialize(config, source_tree) self.config = config self.source_tree = source_tree @server_list = {} @config_list = {} @context = self.config @prev_context = self.config @config_text = "".dup end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/haproxy/renderer.rb', line 6 def config @config end |
#source_tree ⇒ Object
Returns the value of attribute source_tree.
6 7 8 |
# File 'lib/haproxy/renderer.rb', line 6 def source_tree @source_tree end |
Instance Method Details
#render ⇒ Object
18 19 20 21 22 |
# File 'lib/haproxy/renderer.rb', line 18 def render render_node(source_tree) handle_context_change @config_text end |
#render_node(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/haproxy/renderer.rb', line 24 def render_node(node) node.elements.each do |e| update_render_context(e) handle_context_change if context_changed? if e.class == HAProxy::Treetop::ServerLine # Keep track of the servers that we've seen, so that we can detect and render new ones. @server_list[e.name] = e # Don't render the server element if it's been deleted from the config. next if @context.servers[e.name].nil? end if (e.class == HAProxy::Treetop::ConfigLine) && (@context.class == HAProxy::Default) # Keep track of the configs in this config block we've seen, so that # we can detect and render new ones. @config_list[e.key] = e # Don't render the config *if* it's been removed from the config block. next unless @context.config.key?(e.key) end if e.class == HAProxy::Treetop::ServerLine # Use a custom rendering method for servers, since we allow them to be # added/removed/changed. render_server_element(e) elsif (e.class == HAProxy::Treetop::ConfigLine) && (@context.class == HAProxy::Default) # Use a custom rendering method for configs, since we allow them to be # added/removed/changed. render_config_line_element(e) elsif e.elements && e.elements.size > 0 render_node(e) else @config_text << e.text_value end end @config_text end |