Sha256: a9c3e8c6e09462e5213afd8662d6452535ca84c0e699ee6817e8ec3ab3a6f262

Contents?: true

Size: 747 Bytes

Versions: 2

Compression:

Stored size: 747 Bytes

Contents

# frozen_string_literal: true

require 'shoulda-matchers'

module Shoulda
  module Matchers
    module ActiveModel
      def require_a_valid_domain_name(attribute = :domain_name)
        RequireAValidDomainNameMatcher.new(attribute)
      end

      class RequireAValidDomainNameMatcher < ValidationMatcher
        def description
          "require #{@attribute} to be a valid domain name"
        end

        def matches?(subject)
          super(subject)

          disallows_invalid_value && allows_valid_value
        end

        private

        def disallows_invalid_value
          disallows_value_of('example')
        end

        def allows_valid_value
          allows_value_of('example.com')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validates_host-1.3.0 lib/validates_host/require_a_valid_domain_name_matcher.rb
validates_host-1.2.0 lib/validates_host/require_a_valid_domain_name_matcher.rb