Sha256: 0746a0656c78656fa7f0a72459a2cc3deb2c63a277bfab0ec5d5cee4e121bcfd

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

module Percheron
  module Validators
    class Config

      def initialize(config_file)
        @config_file = config_file
      end

      def valid?
        message = rules.return { |rule| send(rule) }
        message ? fail(Errors::ConfigFileInvalid, formatted_message(message)) : true
      end

      private

        attr_reader :config_file

        def formatted_message(message)
          "Config is invalid: #{message}"
        end

        def rules
          [
            :validate_config_file_defined,
            :validate_config_file_existence,
            :validate_config_file_not_empty,
            :validate_config_file_contents
          ]
        end

        def config_file_contents
          @config_file_contents ||= Hashie::Mash.new(YAML.load_file(config_file))
        end

        def validate_config_file_defined
          'Is not defined' if config_file.nil?
        end

        def validate_config_file_existence
          'Does not exist' unless config_file.exist?
        end

        def validate_config_file_not_empty
          'Is empty' if config_file_contents.empty?
        end

        def validate_config_file_contents
          'Is invalid' unless config_file_contents.docker
        end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
percheron-0.7.11 lib/percheron/validators/config.rb
percheron-0.7.10 lib/percheron/validators/config.rb
percheron-0.7.9 lib/percheron/validators/config.rb
percheron-0.7.8 lib/percheron/validators/config.rb
percheron-0.7.7 lib/percheron/validators/config.rb
percheron-0.7.6 lib/percheron/validators/config.rb
percheron-0.7.5 lib/percheron/validators/config.rb
percheron-0.7.4 lib/percheron/validators/config.rb
percheron-0.7.3 lib/percheron/validators/config.rb
percheron-0.7.2 lib/percheron/validators/config.rb