Sha256: f2bc0397521a358bbe7dc89d2c979e8a1a0d26fb6c3ab3a73beaf3a145a8620a

Contents?: true

Size: 749 Bytes

Versions: 4

Compression:

Stored size: 749 Bytes

Contents

require "shoulda-matchers"

module Shoulda
  module Matchers
    module ActiveModel
      def require_a_valid_host_name(attribute = :host_name)
        HostNameMatcher.new(attribute)
      end

      class HostNameMatcher < ValidationMatcher
        def initialize(attribute)
          @attribute = attribute
        end

        def description
          "require #{@attribute} to be a valid host name"
        end

        def matches?(subject)
          super(subject)

          disallows_invalid_value and allows_valid_value
        end

        private

        def disallows_invalid_value
          disallows_value_of("1bd")
        end

        def allows_valid_value
          allows_value_of("bd01")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
validates_host-0.3.1 lib/validates_host/shoulda-matchers/host_name_matcher.rb
validates_host-0.3.0 lib/validates_host/shoulda-matchers/host_name_matcher.rb
validates_host-0.2.0 lib/validates_host/shoulda-matchers/host_name_matcher.rb
validates_host-0.1.0 lib/validates_host/shoulda-matchers/host_name_matcher.rb