Sha256: 50f592ba475d647b8da247864e8038ba8dc56b5643b4523654fa93d7589c606b

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

module Percheron
  module Validators
    class Container

      def initialize(container)
        @container = container
      end

      def valid?
        message = rules.return { |rule| send(rule) }

        if message
          raise Errors::ContainerInvalid.new(formatted_message(message))
        else
          true
        end
      end

      private

        attr_reader :container

        def formatted_message(message)
          if container.name
            "Container config for '%s' is invalid: %s" % [ container.name, message ]
          else
            "Container config is invalid: %s" % [ message ]
          end
        end

        def rules
          [
            :validate_name,
            :validate_version,
            :validate_dockerfile
          ]
        end

        def validate_name
          'Name is invalid' if container.name.nil? || !container.name.to_s.match(/[\w\d]{3,}/)
        end

        def validate_version
          container.version
          nil
        rescue ArgumentError
          'Version is invalid'
        end

        def validate_dockerfile
          'Dockerfile is invalid' if container.dockerfile.nil? || !File.exist?(container.dockerfile)
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
percheron-0.6.4 lib/percheron/validators/container.rb
percheron-0.6.3 lib/percheron/validators/container.rb
percheron-0.6.2 lib/percheron/validators/container.rb
percheron-0.6.1 lib/percheron/validators/container.rb
percheron-0.6.0 lib/percheron/validators/container.rb