Module: RSpecTracer::Configuration
- Included in:
- RSpecTracer
- Defined in:
- lib/rspec_tracer/configuration.rb
Overview
The user-facing configuration DSL. Mixed into ‘RSpecTracer` itself, so calls inside a `.rspec-tracer` (or `~/.rspec-tracer`) file appear against the top-level module:
The DSL methods are technically ‘private` in Ruby; the `configure` block uses Docile to expose them as if public. Calling them outside a `.rspec-tracer` file raises `InvalidUsageError`. The configuration loader allowlist enforces this gate (see ALLOWED_CONFIGURER).
See also:
-
README — user guide.
-
UPGRADING — 1.x → 2.0 migration.
-
ARCHITECTURE — input taxonomy + layer structure.
-
COOKBOOK — recipes for common scenarios.
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: DslTypoSuggester Classes: InvalidUsageError
Constant Summary collapse
- ALLOWED_CONFIGURER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
%w[ lib/rspec_tracer/load_default_config.rb lib/rspec_tracer/load_global_config.rb lib/rspec_tracer/load_local_config.rb ].freeze
- DEFAULT_CACHE_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'rspec_tracer_cache'- DEFAULT_COVERAGE_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'rspec_tracer_coverage'- DEFAULT_REPORT_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'rspec_tracer_report'- DEFAULT_LOCK_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'rspec_tracer.lock'- DEFAULT_STORAGE_BACKEND =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
:json- STORAGE_BACKEND_NAMES =
:sqlite opt-in: MRI >= 3.2 only (sqlite3 2.x gem requirement). Kept closed so typos raise early.
%i[json sqlite].freeze
- STORAGE_BACKEND_OPT_KEYS =
Keys allowed in ‘storage_backend`’s opts hash. ‘:serializer` is accepted only for the :json backend (see validate_storage_opts!).
%i[serializer].freeze
- STORAGE_BACKEND_SERIALIZERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
%i[json msgpack].freeze
- DEFAULT_CACHE_RETENTION_LOCAL_COUNT =
Per-save retention on the local cache’s run-id directories. 5 keeps enough history for rollback debugging without letting the cache grow unbounded (issue #20). 0 opts out entirely.
5- DEFAULT_CACHE_SIZE_WARN_PER_FILE_MB =
Size budgets (MiB). Warn at save time when any single cache file exceeds the per-file threshold or when the cache total exceeds the aggregate threshold. Surfaces B11 symptoms (dependency.json ballooning past the few-MB range) while the user can still act on them. Set to 0 to disable either individually.
50- DEFAULT_CACHE_SIZE_WARN_TOTAL_MB =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
500- LOG_LEVEL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
{ off: 0, debug: 1, info: 2, warn: 3, error: 4 }.freeze
Instance Method Summary collapse
-
#configure ⇒ Object
private
Internal method on the tracer pipeline.
-
#method_missing(name, *args, **kwargs) ⇒ Object
Catches typos in ‘.rspec-tracer` config files.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
private
Internal method on the tracer pipeline.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs) ⇒ Object
Catches typos in ‘.rspec-tracer` config files. When the user mistypes a DSL name (e.g. `track_files_glob` for `track_files`), bare `NoMethodError` puts a Ruby backtrace in their face. This surface raises `InvalidUsageError` with a stdlib `DidYouMean` suggestion when the typo is close to a known DSL method; otherwise it falls through to NoMethodError so internal respond_to? probes / non-DSL undefined-method usage retains standard Ruby semantics.
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
# File 'lib/rspec_tracer/configuration.rb', line 1317 def method_missing(name, *args, **kwargs, &) return super if name.to_s.end_with?('=') candidates = RSpecTracer::Configuration::DslTypoSuggester.candidates suggestion = candidates.empty? ? nil : RSpecTracer::Configuration::DslTypoSuggester.nearest(name.to_s, candidates) return super if suggestion.nil? raise InvalidUsageError, "unknown .rspec-tracer DSL method #{name.inspect}; did you mean #{suggestion.inspect}?" end |
Instance Method Details
#configure ⇒ 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rspec_tracer/configuration.rb', line 106 def configure(&) # Scan the full caller chain (not just the immediate two frames): # MRI / JRuby place the load_*_config.rb loader at depth 2, but # TruffleRuby's `load` interposes an extra runtime frame, pushing # the loader past the 2-frame window and tripping the InvalidUsage # raise. Path-suffix match against the well-known loader filenames # keeps the gate safe regardless of stack depth - user code would # have to copy one of those filenames verbatim into a path it # `load`s to get a false positive, which we treat as wilful. configurers = caller_locations(1).map(&:path) invalid = configurers.none? do |configurer| ALLOWED_CONFIGURER.any? do |allowed_configurer| configurer.end_with?(allowed_configurer) end end raise InvalidUsageError, 'You must define configurations in a .rspec-tracer file' if invalid RSpecTracer::Configuration.module_exec do RSpecTracer::Configuration.private_instance_methods(false).each do |method_name| alias_method :"_#{method_name}", method_name # Forward `**kwargs` too so DSL methods can accept Ruby 3+ # keyword args (e.g. `track_rails_defaults except: [:views]`, # `storage_backend :json, serializer: :msgpack`). Earlier # forms of this wrapper forwarded `*args, &block` only and # silently stripped kwargs. define_method method_name do |*args, **kwargs, &block| send(:"_#{method_name}", *args, **kwargs, &block) end end end Docile.dsl_eval(self, &) end |
#respond_to_missing?(name, include_private = false) ⇒ 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.
1330 1331 1332 |
# File 'lib/rspec_tracer/configuration.rb', line 1330 def respond_to_missing?(name, include_private = false) super end |