Class: I18n::Tasks::Scanners::PrismScanners::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/tasks/scanners/prism_scanners/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node: nil, parent: nil, file_path: nil, rails: false) ⇒ Root

Returns a new instance of Root.



9
10
11
12
13
14
15
16
17
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 9

def initialize(node: nil, parent: nil, file_path: nil, rails: false)
  @calls = []
  @translation_calls = []
  @children = []
  @node = node
  @parent = parent
  @rails = rails
  @file_path = file_path
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def calls
  @calls
end

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def children
  @children
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def file_path
  @file_path
end

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def parent
  @parent
end

#railsObject (readonly)

Returns the value of attribute rails.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def rails
  @rails
end

#translation_callsObject (readonly)

Returns the value of attribute translation_calls.



7
8
9
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 7

def translation_calls
  @translation_calls
end

Instance Method Details

#add_call(node) ⇒ Object



24
25
26
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 24

def add_call(node)
  @calls << node
end

#add_child(node) ⇒ Object



19
20
21
22
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 19

def add_child(node)
  @children << node
  node
end

#add_translation_call(translation_call) ⇒ Object



28
29
30
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 28

def add_translation_call(translation_call)
  @translation_calls += Array(translation_call)
end

#partial_view?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 36

def partial_view?
  file_path.present? && File.basename(file_path).start_with?("_")
end

#pathObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 48

def path
  if rails_view?
    folder_path = file_path.sub(%r{app/views/}, "").split("/")
    name = folder_path.pop.split(".").first

    [*folder_path, name]
  else
    []
  end
end

#private_methodObject

Only supported for Rails controllers currently



64
65
66
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 64

def private_method
  false
end

#processObject



59
60
61
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 59

def process
  (@translation_calls + @children.flat_map(&:process)).flatten
end

#rails_view?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 32

def rails_view?
  rails && file_path.present? && file_path.include?("app/views/")
end

#support_candidate_keys?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 44

def support_candidate_keys?
  false
end

#support_relative_keys?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 40

def support_relative_keys?
  rails_view? && !partial_view?
end