This file is indexed.

/usr/lib/ruby/vendor_ruby/shoulda/matchers/active_record/validate_format_of_matcher.rb is in ruby-shoulda-matchers 1.0.0~beta2-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Shoulda # :nodoc:
  module Matchers
    module ActiveRecord # :nodoc:

      # Ensures that the model is not valid if the given attribute is not
      # formatted correctly.
      #
      # Options:
      # * <tt>with_message</tt> - value the test expects to find in
      #   <tt>errors.on(:attribute)</tt>. <tt>Regexp</tt> or <tt>String</tt>.
      #   Defaults to the translation for <tt>:invalid</tt>.
      # * <tt>with(string to test against)</tt>
      # * <tt>not_with(string to test against)</tt>
      #
      # Examples:
      #   it { should validate_format_of(:name).
      #                 with('12345').
      #                 with_message(/is not optional/) }
      #   it { should validate_format_of(:name).
      #                 not_with('12D45').
      #                 with_message(/is not optional/) }
      #
      def validate_format_of(attr)
        ValidateFormatOfMatcher.new(attr)
      end

      class ValidateFormatOfMatcher < ValidationMatcher # :nodoc:

        def initialize(attribute)
          super
        end

        def with_message(message)
          @expected_message = message if message
          self
        end

        def with(value)
          raise "You may not call both with and not_with" if @value_to_fail
          @value_to_pass = value
          self
        end

        def not_with(value)
          raise "You may not call both with and not_with" if @value_to_pass
          @value_to_fail = value
          self
        end

        def matches?(subject)
          super(subject)
          @expected_message ||= :invalid
          return disallows_value_of(@value_to_fail, @expected_message) if @value_to_fail
          allows_value_of(@value_to_pass, @expected_message) if @value_to_pass
        end

        def description
          "#{@attribute} have a valid format"
        end

      end

    end
  end
end