123456789_123456789_123456789_123456789_123456789_

Class: ActionView::DependencyTracker::ERBTracker

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionview/lib/action_view/dependency_tracker/erb_tracker.rb

Constant Summary

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, template, view_paths = nil) ⇒ ERBTracker

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 72

def initialize(name, template, view_paths = nil)
  @name, @template, @view_paths = name, template, view_paths
end

Class Attribute Details

.supports_view_paths?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 64

def self.supports_view_paths? # :nodoc:
  true
end

Class Method Details

.call(name, template, view_paths = nil)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 68

def self.call(name, template, view_paths = nil)
  new(name, template, view_paths).dependencies
end

Instance Attribute Details

#name (readonly, private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 80

attr_reader :name, :template

#template (readonly, private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 80

attr_reader :name, :template

Instance Method Details

#add_dependencies(render_dependencies, arguments, pattern) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 104

def add_dependencies(render_dependencies, arguments, pattern)
  arguments.scan(pattern) do
    match = Regexp.last_match
    add_dynamic_dependency(render_dependencies, match[:dynamic])
    add_static_dependency(render_dependencies, match[:static], match[:quote])
  end
end

#add_dynamic_dependency(dependencies, dependency) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 112

def add_dynamic_dependency(dependencies, dependency)
  if dependency
    dependencies << "#{dependency.pluralize}/#{dependency.singularize}"
  end
end

#add_static_dependency(dependencies, dependency, quote_type) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 118

def add_static_dependency(dependencies, dependency, quote_type)
  if quote_type == '"' && dependency.include?('#{')
    scanner = StringScanner.new(dependency)

    wildcard_dependency = +""

    while !scanner.eos?
      if scanner.scan_until(/\#{/)
        unmatched_brackets = 1
        wildcard_dependency << scanner.pre_match

        while unmatched_brackets > 0 && !scanner.eos?
          found = scanner.scan_until(/[{}]/)
          return unless found

          case scanner.matched
          when "{"
            unmatched_brackets += 1
          when "}"
            unmatched_brackets -= 1
          end
        end

        wildcard_dependency << "*"
      else
        wildcard_dependency << scanner.rest
        scanner.terminate
      end
    end

    dependencies << wildcard_dependency
  elsif dependency
    if dependency.include?("/")
      dependencies << dependency
    else
      dependencies << "#{directory}/#{dependency}"
    end
  end
end

#dependencies

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 76

def dependencies
  WildcardResolver.new(@view_paths, render_dependencies + explicit_dependencies).resolve
end

#directory (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 88

def directory
  name.split("/")[0..-2].join("/")
end

#explicit_dependencies (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 158

def explicit_dependencies
  source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
end

#render_dependencies (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 92

def render_dependencies
  dependencies = []
  render_calls = source.split(/\brender\b/).drop(1)

  render_calls.each do |arguments|
    add_dependencies(dependencies, arguments, LAYOUT_DEPENDENCY)
    add_dependencies(dependencies, arguments, RENDER_ARGUMENTS)
  end

  dependencies
end

#source (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 84

def source
  template.source
end