Sha256: 1d2157f9e0a2c5e419a877e87f985168128b6709977c1a3be51bf5b3af3a06ad

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

require "shoulda-matchers"

module Shoulda
  module Matchers
    module ActiveModel
      def require_a_valid_subnet(attribute = :value)
        RequireAValidSubnetMatcher.new(attribute)
      end

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

        def description
          "require #{@attribute} to be a valid subnet"
        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/28")
        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_subnet_matcher.rb