Sha256: 2f2f1b7447c13228d6590eb3b0e708019b7d5d3c99a540c51f11ef7a144546f8

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'phut/configuration'
require 'phut/null_logger'
require 'phut/syntax'

module Phut
  # Configuration DSL parser.
  class Parser
    def initialize(logger = NullLogger.new)
      @config = Configuration.new(logger)
      @port_number = Hash.new(0)
    end

    def parse(file)
      Syntax.new(@config).instance_eval IO.read(file), file
      connect_links_to_switches
      connect_links_to_vhosts
      @config
    end

    private

    def connect_links_to_switches
      @config.links.each do |each|
        maybe_assign_network_device_to_vswitch each
      end
    end

    def connect_links_to_vhosts
      @config.vhosts.each do |each|
        each.network_device = @config.find_network_device_by_name(each.name)
      end
    end

    def maybe_assign_network_device_to_vswitch(link)
      @config.vswitches.each do |each|
        switch_name = each.name
        network_device = link.find_network_device_by_name(switch_name)
        next unless network_device
        network_device.port_number = new_port_number(switch_name)
        each.network_devices << network_device
      end
    end

    def new_port_number(switch_name)
      @port_number[switch_name] += 1
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
phut-0.6.2 lib/phut/parser.rb
phut-0.6.1 lib/phut/parser.rb
phut-0.6.0 lib/phut/parser.rb
phut-0.5.0 lib/phut/parser.rb
phut-0.4.0 lib/phut/parser.rb