instance method find_in

Ruby on Rails 8.1.2

Since v6.0.6

Available in: v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

find_in(dir)

Returns a hash that maps filenames under dir (recursively) to arrays with their annotations. Files with extensions registered in Rails::SourceAnnotationExtractor::Annotation.extensions are taken into account. Only files with annotations are included.

Parameters

dir req
Source
# File railties/lib/rails/source_annotation_extractor.rb, line 172
    def find_in(dir)
      results = {}

      Dir.glob("#{dir}/*") do |item|
        next if File.basename(item).start_with?(".")

        if File.directory?(item)
          results.update(find_in(item))
        else
          extension = Annotation.extensions.detect do |regexp, _block|
            regexp.match(item)
          end

          if extension
            pattern = extension.last.call(tag)

            # In case a user-defined pattern returns nothing for the given set
            # of tags, we exit early.
            next unless pattern

            # If a user-defined pattern returns a regular expression, we will
            # wrap it in a PatternExtractor to keep the same API.
            pattern = PatternExtractor.new(pattern) if pattern.is_a?(Regexp)

            annotations = pattern.annotations(item)
            results.update(item => annotations) if annotations.any?
          end
        end
      end

      results
    end

Defined in railties/lib/rails/source_annotation_extractor.rb line 172 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::SourceAnnotationExtractor

Type at least 2 characters to search.

↑↓ navigate · open · esc close