Sha256: 7b797a338c589415ef9d033315a67a2aacc6d0b90d6a3862ca0ad8930dc0aa05

Contents?: true

Size: 702 Bytes

Versions: 2

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

require 'shoulda-matchers'

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

      class RequireAValidIpMatcher < ValidationMatcher
        def description
          "require #{@attribute} to be a valid ip"
        end

        def matches?(subject)
          super(subject)

          disallows_invalid_value && 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

2 entries across 2 versions & 1 rubygems

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