Class: I18n::Tasks::Scanners::PrismScanners::ParsedClass
- Inherits:
-
Root
- Object
- Root
- I18n::Tasks::Scanners::PrismScanners::ParsedClass
show all
- Defined in:
- lib/i18n/tasks/scanners/prism_scanners/nodes.rb
Instance Attribute Summary collapse
Attributes inherited from Root
#calls, #children, #file_path, #node, #parent, #rails, #translation_calls
Instance Method Summary
collapse
Methods inherited from Root
#add_call, #add_translation_call, #partial_view?, #rails_view?
Constructor Details
#initialize(node:, parent:, rails:) ⇒ ParsedClass
Returns a new instance of ParsedClass.
217
218
219
220
221
222
223
224
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 217
def initialize(node:, parent:, rails:)
@private_method = false
@methods = []
@private_methods = []
@before_actions = []
super
end
|
Instance Attribute Details
#private_method ⇒ Object
Returns the value of attribute private_method.
215
216
217
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 215
def private_method
@private_method
end
|
Instance Method Details
#add_child(node) ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 226
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
|
#controller? ⇒ Boolean
318
319
320
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 318
def controller?
@rails && @node.name.to_s.end_with?("Controller")
end
|
#mailer? ⇒ Boolean
322
323
324
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 322
def mailer?
@rails && @node.name.to_s.end_with?("Mailer")
end
|
#path ⇒ Object
314
315
316
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 314
def path
(@parent&.path || []) + [path_name]
end
|
#path_name ⇒ Object
326
327
328
329
330
331
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 326
def path_name
path = @node.constant_path.full_name_parts.map { |s| s.to_s.underscore }
path.last.delete_suffix!("_controller") if controller?
path
end
|
#private_methods! ⇒ Object
302
303
304
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 302
def private_methods!
@private_method = true
end
|
#process ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
241
242
243
244
245
246
247
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 241
def process if controller?
process_controller
else
super
end
end
|
#process_controller ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 249
def process_controller
methods_by_name = @methods.group_by(&:name)
private_methods_by_name = @private_methods.group_by(&:name)
@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
@methods.each do |method|
next unless before_action.applies_to?(method.name)
method.add_translation_call(
translation_calls.map do |call|
call.with_parent(method)
end
)
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)
next
end
other_method.translation_calls.each do |translation_call|
new_translation_calls.push(translation_call.with_parent(method))
end
end
end
@translation_calls + @children.flat_map(&:process) + new_translation_calls
end
|
#support_candidate_keys? ⇒ Boolean
310
311
312
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 310
def support_candidate_keys?
controller?
end
|
#support_relative_keys? ⇒ Boolean
306
307
308
|
# File 'lib/i18n/tasks/scanners/prism_scanners/nodes.rb', line 306
def support_relative_keys?
controller? || mailer?
end
|