Sha256: 1f1d69d052b6de0c2a0d8629911c8a8845cce37b3f628b0f596b4e131622545d

Contents?: true

Size: 725 Bytes

Versions: 4

Compression:

Stored size: 725 Bytes

Contents

require "shoulda-matchers"

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

      class IpMatcher < 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

4 entries across 4 versions & 1 rubygems

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