Sha256: 7f3b8c4a71546961f078daff5cf52f65d8bea8795357643d66fe4171db897eef

Contents?: true

Size: 961 Bytes

Versions: 13

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module ActionView
  class DependencyTracker # :nodoc:
    class WildcardResolver # :nodoc:
      def initialize(view_paths, dependencies)
        @view_paths = view_paths

        @wildcard_dependencies, @explicit_dependencies =
          dependencies.partition { |dependency| dependency.end_with?("/*") }
      end

      def resolve
        return explicit_dependencies.uniq if !view_paths || wildcard_dependencies.empty?

        (explicit_dependencies + resolved_wildcard_dependencies).uniq
      end

      private
        attr_reader :explicit_dependencies, :wildcard_dependencies, :view_paths

        def resolved_wildcard_dependencies
          # Remove trailing "/*"
          prefixes = wildcard_dependencies.map { |query| query[0..-3] }

          view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
            path.to_s if prefixes.include?(path.prefix)
          }.sort
        end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
actionview-8.0.1 lib/action_view/dependency_tracker/wildcard_resolver.rb
actionview-8.0.0.1 lib/action_view/dependency_tracker/wildcard_resolver.rb
actionview-8.0.0 lib/action_view/dependency_tracker/wildcard_resolver.rb
actionview-8.0.0.rc2 lib/action_view/dependency_tracker/wildcard_resolver.rb
actionview-8.0.0.rc1 lib/action_view/dependency_tracker/wildcard_resolver.rb
actionview-8.0.0.beta1 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha9 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha8 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha7 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha4 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha3 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha2 lib/action_view/dependency_tracker/wildcard_resolver.rb
omg-actionview-8.0.0.alpha1 lib/action_view/dependency_tracker/wildcard_resolver.rb