Sha256: 3c01e3fdca19bd9e69049099bc4ded79335f2e5f485536e20ee75764e679173c

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'taketo/config_traverser'
require 'taketo/config_visitor'

module Taketo
  class ConfigError < StandardError; end

  class ConfigValidatorVisitor < ConfigVisitor
    def initialize
      @global_server_aliases = {}
    end

    visit Config do |c|
      raise ConfigError, "There are no servers. Add some to your config (~/.taketo.rc.rb by default)" unless c.has_servers?
    end

    visit Project do |p|
      raise ConfigError, "Project #{p.path}: no environments" unless p.has_environments?
    end

    visit Environment do |e|
      raise ConfigError, "Environment #{e.path}: no servers" unless e.has_servers?
    end

    visit Server do |s|
      if !String(s.global_alias).empty?
        if @global_server_aliases.key?(s.global_alias)
          raise ConfigError, "Server #{s.path}: global alias '#{s.global_alias}' has already been taken by server #{@global_server_aliases[s.global_alias].path}"
        else
          @global_server_aliases[s.global_alias] = s
        end
      end

      raise ConfigError, "Server #{s.path}: host is not defined" if String(s.host).empty?
    end

    visit Command do |c|
      raise ConfigError, "Don't know what to execute on command #{c.name}" if String(c.command).empty?
    end
  end

  class ConfigValidator
    def initialize(traverser)
      @traverser = traverser
    end

    def validate!
      @traverser.visit_depth_first(ConfigValidatorVisitor.new)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
taketo-0.1.0 lib/taketo/config_validator.rb