class I18n::Tasks::Scanners::PrismScanners::ParsedClass
Attributes
Public Class Methods
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 177 def initialize(node:, parent:, rails:) @private_method = false @methods = [] @private_methods = [] @before_actions = [] @rails = rails super(node: node, parent: parent) end
Calls superclass method
I18n::Tasks::Scanners::PrismScanners::Root::new
Public Instance Methods
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 187 def add_child(node) case node when ParsedMethod if @private_method @private_methods << node else @methods << node end when ParsedBeforeAction @before_actions << node end super end
Calls superclass method
I18n::Tasks::Scanners::PrismScanners::Root#add_child
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 267 def controller? @node.name.to_s.end_with?('Controller') end
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 263 def path (@parent&.path || []) + [path_name] end
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 271 def path_name path = @node.constant_path.full_name_parts.map { |s| s.to_s.underscore } path.last.gsub!(/_controller\z/, '') if controller? path end
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 255 def private_methods! @private_method = true end
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 202 def process # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity return @children.flat_map(&:process) unless controller? methods_by_name = @methods.group_by(&:name) private_methods_by_name = @private_methods.group_by(&:name) # For each before_action we need to # - Find which method it calls # - Find out which methods it applies to # - Calculate translation calls (and see if they are relative) # - Add the translation calls to the methods it applies to @before_actions.each do |before_action| before_action_name = before_action.name&.to_sym method_call = methods_by_name[before_action_name]&.first || private_methods_by_name[before_action_name]&.first translation_calls = (method_call&.translation_calls || []) + before_action.translation_calls # We need to handle the parent here, should not be the before_action when it is called in the method. @methods.each do |method| next unless before_action.applies_to?(method.name) method.add_translation_call( translation_calls.map { |call| call.with_parent(method) } ) end end nested_calls = {} new_translation_calls = [] @methods.each do |method| method.calls.each do |call| next if call.receiver.present? other_method = methods_by_name[call.name]&.first || private_methods_by_name[call.name]&.first next unless other_method nested_calls[method.name] ||= [] nested_calls[method.name] << other_method.name if nested_calls[call.name]&.include?(method.name) fail(ArgumentError, "Cyclic call detected: #{call.name} -> #{method.name}") end other_method.translation_calls.each do |translation_call| new_translation_calls.push(translation_call.with_parent(method)) end end end @children.flat_map(&:process) + new_translation_calls end
Source
# File lib/i18n/tasks/scanners/prism_scanners/nodes.rb, line 259 def support_relative_keys? @rails && controller? end