Class: ActionView::DependencyTracker::ERBTracker

Inherits:
Object
  • Object
show all
Defined in:
actionview/lib/action_view/dependency_tracker/erb_tracker.rb

Overview

:nodoc:

Constant Summary collapse

EXPLICIT_DEPENDENCY =
/# Template Dependency: (\S+)/
IDENTIFIER =

A valid ruby identifier - suitable for class, method and specially variable names

/
  [[:alpha:]_] # at least one uppercase letter, lowercase letter or underscore
  [[:word:]]*  # followed by optional letters, numbers or underscores
/x
VARIABLE_OR_METHOD_CHAIN =

Any kind of variable name. e.g. @instance, @@class, $global or local. Possibly following a method call chain

/
  (?:\$|@{1,2})?            # optional global, instance or class variable indicator
  (?:#{IDENTIFIER}\.)*      # followed by an optional chain of zero-argument method calls
  (?<dynamic>#{IDENTIFIER}) # and a final valid identifier, captured as DYNAMIC
/x
STRING =

A simple string literal. e.g. “School’s out!”

/
  (?<quote>['"]) # an opening quote
  (?<static>.*?) # with anything inside, captured as STATIC
  \k<quote>      # and a matching closing quote
/x
PARTIAL_HASH_KEY =

Part of any hash containing the :partial key

/
  (?:\bpartial:|:partial\s*=>) # partial key in either old or new style hash syntax
  \s*                          # followed by optional spaces
/x
LAYOUT_HASH_KEY =

Part of any hash containing the :layout key

/
  (?:\blayout:|:layout\s*=>)   # layout key in either old or new style hash syntax
  \s*                          # followed by optional spaces
/x
RENDER_ARGUMENTS =

Matches:

partial: "comments/comment", collection: @all_comments => "comments/comment"
(object: @single_comment, partial: "comments/comment") => "comments/comment"

"comments/comments"
'comments/comments'
('comments/comments')

(@topic)         => "topics/topic"
 topics          => "topics/topic"
(message.topics) => "topics/topic"
/\A
  (?:\s*\(?\s*)                                  # optional opening paren surrounded by spaces
  (?:.*?#{PARTIAL_HASH_KEY}|#{LAYOUT_HASH_KEY})? # optional hash, up to the partial or layout key declaration
  (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN})      # finally, the dependency name of interest
/xm
LAYOUT_DEPENDENCY =
/\A
  (?:\s*\(?\s*)                                  # optional opening paren surrounded by spaces
  (?:.*?#{LAYOUT_HASH_KEY})                      # check if the line has layout key declaration
  (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN})      # finally, the dependency name of interest
/xm

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template, view_paths = nil) ⇒ ERBTracker

Returns a new instance of ERBTracker.



72
73
74
# 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 Method Details

.call(name, template, view_paths = nil) ⇒ Object



68
69
70
# 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

.supports_view_paths?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def self.supports_view_paths? # :nodoc:
  true
end

Instance Method Details

#dependenciesObject



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

def dependencies
  render_dependencies + explicit_dependencies
end