Class: I18n::Tasks::Scanners::PrismScanners::Root
- Inherits:
-
Object
- Object
- I18n::Tasks::Scanners::PrismScanners::Root
- Defined in:
- lib/i18n/tasks/scanners/prism_scanners/nodes.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#rails ⇒ Object
readonly
Returns the value of attribute rails.
-
#translation_calls ⇒ Object
readonly
Returns the value of attribute translation_calls.
Instance Method Summary collapse
- #add_call(node) ⇒ Object
- #add_child(node) ⇒ Object
- #add_translation_call(translation_call) ⇒ Object
-
#initialize(node: nil, parent: nil, file_path: nil, rails: false) ⇒ Root
constructor
A new instance of Root.
- #partial_view? ⇒ Boolean
- #path ⇒ Object
-
#private_method ⇒ Object
Only supported for Rails controllers currently.
- #process ⇒ Object
- #rails_view? ⇒ Boolean
- #support_candidate_keys? ⇒ Boolean
- #support_relative_keys? ⇒ Boolean
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
#calls ⇒ Object (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 |
#children ⇒ Object (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_path ⇒ Object (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 |
#node ⇒ Object (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 |
#parent ⇒ Object (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 |
#rails ⇒ Object (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_calls ⇒ Object (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
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 |
#path ⇒ Object
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_method ⇒ Object
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 |
#process ⇒ Object
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
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
44 45 46 |
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 44 def support_candidate_keys? false end |
#support_relative_keys? ⇒ Boolean
40 41 42 |
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 40 def support_relative_keys? rails_view? && !partial_view? end |