Sha256: e584605aa8ebc01db184a0b7b1cb9e28ff0c9df3d4fd5130fd5a63b9c1cbeb54

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

require "shoulda-matchers"

module Shoulda
  module Matchers
    module ActiveModel
      def require_a_valid_ip(attribute = :ip)
        RequireAValidIpMatcher.new(attribute)
      end

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

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

        def matches?(subject)
          super(subject)

          disallows_invalid_value and allows_valid_value
        end

        private

        def disallows_invalid_value
          disallows_value_of("10.0.0")
        end

        def allows_valid_value
          allows_value_of("10.10.10.1")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_host-1.0.0 lib/validates_host/require_a_valid_ip_matcher.rb