Class: PlatformosCheck::UndefinedObject::TemplateInfo
- Inherits:
-
Object
- Object
- PlatformosCheck::UndefinedObject::TemplateInfo
- Defined in:
- lib/platformos_check/checks/undefined_object.rb
Instance Attribute Summary collapse
-
#all_assigns ⇒ Object
readonly
Returns the value of attribute all_assigns.
-
#all_captures ⇒ Object
readonly
Returns the value of attribute all_captures.
-
#all_forloops ⇒ Object
readonly
Returns the value of attribute all_forloops.
-
#all_renders ⇒ Object
readonly
Returns the value of attribute all_renders.
-
#app_file ⇒ Object
readonly
Returns the value of attribute app_file.
Instance Method Summary collapse
- #add_render(name:, node:) ⇒ Object
- #add_variable_lookup(name:, node:) ⇒ Object
- #all_variables ⇒ Object
- #each_partial ⇒ Object
- #each_variable_lookup(unique_keys = false) ⇒ Object
- #first_declaration(name) ⇒ Object
-
#initialize(app_file: nil) ⇒ TemplateInfo
constructor
A new instance of TemplateInfo.
Constructor Details
#initialize(app_file: nil) ⇒ TemplateInfo
Returns a new instance of TemplateInfo.
13 14 15 16 17 18 19 20 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 13 def initialize(app_file: nil) @all_variable_lookups = {} @all_assigns = {} @all_captures = {} @all_forloops = {} @all_renders = {} @app_file = app_file end |
Instance Attribute Details
#all_assigns ⇒ Object (readonly)
Returns the value of attribute all_assigns.
22 23 24 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 22 def all_assigns @all_assigns end |
#all_captures ⇒ Object (readonly)
Returns the value of attribute all_captures.
22 23 24 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 22 def all_captures @all_captures end |
#all_forloops ⇒ Object (readonly)
Returns the value of attribute all_forloops.
22 23 24 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 22 def all_forloops @all_forloops end |
#all_renders ⇒ Object (readonly)
Returns the value of attribute all_renders.
22 23 24 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 22 def all_renders @all_renders end |
#app_file ⇒ Object (readonly)
Returns the value of attribute app_file.
22 23 24 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 22 def app_file @app_file end |
Instance Method Details
#add_render(name:, node:) ⇒ Object
24 25 26 27 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 24 def add_render(name:, node:) @all_renders[name] ||= [] @all_renders[name] << node end |
#add_variable_lookup(name:, node:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 29 def add_variable_lookup(name:, node:) parent = node line_number = nil loop do line_number = parent.line_number parent = parent.parent break unless line_number.nil? && parent end key = [name, line_number] @all_variable_lookups[key] = node end |
#all_variables ⇒ Object
41 42 43 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 41 def all_variables all_assigns.keys + all_captures.keys + all_forloops.keys end |
#each_partial ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 45 def each_partial @all_renders.each do |(name, nodes)| nodes.each do |node| yield [name, node] end end end |
#each_variable_lookup(unique_keys = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 53 def each_variable_lookup(unique_keys = false) seen = Set.new @all_variable_lookups.each do |(key, info)| name, _line_number = key next if unique_keys && seen.include?(name) seen << name yield [key, info] end end |
#first_declaration(name) ⇒ Object
66 67 68 |
# File 'lib/platformos_check/checks/undefined_object.rb', line 66 def first_declaration(name) [all_assigns[name], all_captures[name]].compact.min_by(&:line_number) end |