Class: ThemeCheck::UndefinedObject::TemplateInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/checks/undefined_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemplateInfo

Returns a new instance of TemplateInfo.



9
10
11
12
13
14
15
# File 'lib/theme_check/checks/undefined_object.rb', line 9

def initialize
  @all_variable_lookups = {}
  @all_assigns = {}
  @all_captures = {}
  @all_forloops = {}
  @all_renders = {}
end

Instance Attribute Details

#all_assignsObject (readonly)

Returns the value of attribute all_assigns.



17
18
19
# File 'lib/theme_check/checks/undefined_object.rb', line 17

def all_assigns
  @all_assigns
end

#all_capturesObject (readonly)

Returns the value of attribute all_captures.



17
18
19
# File 'lib/theme_check/checks/undefined_object.rb', line 17

def all_captures
  @all_captures
end

#all_forloopsObject (readonly)

Returns the value of attribute all_forloops.



17
18
19
# File 'lib/theme_check/checks/undefined_object.rb', line 17

def all_forloops
  @all_forloops
end

Instance Method Details

#add_render(name:, node:) ⇒ Object



19
20
21
# File 'lib/theme_check/checks/undefined_object.rb', line 19

def add_render(name:, node:)
  @all_renders[name] = node
end

#add_variable_lookup(name:, node:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/theme_check/checks/undefined_object.rb', line 23

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_variablesObject



35
36
37
# File 'lib/theme_check/checks/undefined_object.rb', line 35

def all_variables
  all_assigns.keys + all_captures.keys + all_forloops.keys
end

#each_snippetObject



39
40
41
42
43
# File 'lib/theme_check/checks/undefined_object.rb', line 39

def each_snippet
  @all_renders.each do |(name, info)|
    yield [name, info]
  end
end

#each_variable_lookup(unique_keys = false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/theme_check/checks/undefined_object.rb', line 45

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