Class: RSpecTracer::Rails::I18nTracking Private
- Inherits:
-
Object
- Object
- RSpecTracer::Rails::I18nTracking
- Defined in:
- lib/rspec_tracer/rails/i18n_tracking.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
I18n backend observer. Covers custom backends (Redis-backed, DB-backed, Chain) that bypass YAML.load_file and would otherwise miss the IOHooks YAML hook.
Mechanism: Module#prepend onto ::I18n::Backend::Base - every backend subclass’s load_translations resolves through the hook, even when the subclass overrides and super-calls Base. Backends that never super-call Base#load_translations fall through the hook, but the common backends (Simple, Chain, Cascade) all do.
Shares Notifications’ thread-local bucket so Engine.setup opens and clears one bucket per example that covers both observer families. Engine harvests ‘bucket.values` at example_finished.
Graceful degradation:
-
install no-ops if ::I18n::Backend::Base is absent (tracer boot survives even in weird I18n-free app graphs).
-
Every record call swallows StandardError (CLAUDE.md) - a digest failure or bucket-shape surprise never propagates into the user’s test run.
Defined Under Namespace
Modules: LoadTranslationsHook
Class Attribute Summary collapse
-
.root ⇒ Object
readonly
private
Internal attribute.
Class Method Summary collapse
-
.install(root:, filter: ->(_path) { true }) ⇒ Object
private
Internal method on the tracer pipeline.
-
.installed? ⇒ Boolean
private
Internal method on the tracer pipeline.
-
.record_translation(path) ⇒ Object
private
Pure-logic entry point.
-
.record_translations(filenames) ⇒ Object
private
Called from LoadTranslationsHook for every filename passed to I18n::Backend::Base#load_translations.
-
.uninstall ⇒ Object
private
Prepended modules cannot be removed from the ancestry chain (Ruby has no public API), mirroring IOHooks.uninstall.
Class Attribute Details
.root ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal attribute.
35 36 37 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 35 def root @root end |
Class Method Details
.install(root:, filter: ->(_path) { true }) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method on the tracer pipeline.
39 40 41 42 43 44 45 46 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 39 def install(root:, filter: ->(_path) { true }) @root = File.(root) @root_prefix = "#{@root}/" @filter = filter @prepended = prepend_backend_hook self end |
.installed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method on the tracer pipeline.
62 63 64 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 62 def installed? !@root_prefix.nil? end |
.record_translation(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pure-logic entry point. Same fast-reject ladder as Notifications#record_template. Emits :notification kind so the I18n source is distinguishable from template events in downstream reporters. The ladder is longer than rubocop’s perceived-complexity threshold by design - each guard is a cheap fast-reject. rubocop:disable Metrics/PerceivedComplexity
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 83 def record_translation(path) return nil if @root_prefix.nil? bucket = Notifications.current_bucket return nil if bucket.nil? return nil unless path.is_a?(String) || path.respond_to?(:to_s) path_str = path.to_s return nil unless path_str.start_with?(@root_prefix) return nil unless @filter.call(path_str) identity = "notification:#{path_str[@root_prefix.length..]}" return nil if bucket.key?(identity) digest = Tracker::FileDigest.compute(path_str) return nil if digest.nil? bucket[identity] = Tracker::Input.for_file( path: path_str, kind: :notification, digest: digest, root: @root ) rescue StandardError nil end |
.record_translations(filenames) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called from LoadTranslationsHook for every filename passed to I18n::Backend::Base#load_translations. Array form keeps the hook a single call site.
69 70 71 72 73 74 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 69 def record_translations(filenames) return nil if @root_prefix.nil? Array(filenames).each { |path| record_translation(path) } nil end |
.uninstall ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepended modules cannot be removed from the ancestry chain (Ruby has no public API), mirroring IOHooks.uninstall. Every hook entry point fast-rejects on @root_prefix nil once install state clears, so post-uninstall the hook is a no-op.
52 53 54 55 56 57 58 |
# File 'lib/rspec_tracer/rails/i18n_tracking.rb', line 52 def uninstall @root = nil @root_prefix = nil @filter = nil @prepended = false self end |