Sha256: 49757489f068de0041ca230b1622bece212de5af40622bf83e1b56747428e76a

Contents?: true

Size: 964 Bytes

Versions: 4

Compression:

Stored size: 964 Bytes

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(message)
        else
          true
        end
      end

      private

        attr_reader :container

        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
          'Version is invalid' if container.version.nil? || !container.version.to_s.match(/[\w\d]{1,}/)
        end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
percheron-0.2.3 lib/percheron/validators/container.rb
percheron-0.2.2 lib/percheron/validators/container.rb
percheron-0.2.1 lib/percheron/validators/container.rb
percheron-0.2.0 lib/percheron/validators/container.rb