Module: HeapScope::ConfigLoader
- Defined in:
- lib/heapscope/config.rb
Overview
Load Ruby or YAML configuration files.
Constant Summary collapse
- STARTER_YAML =
<<~YAML # HeapScope local config — no telemetry, no uploads heapscope: mode: standard track_allocations: false apply_noise_defaults: true detect_globals: true detect_fibers: true detect_closures: false detect_thread_locals: true retention: min_cycles: 3 ignore_patterns: - "^Zeitwerk" - "^Bootsnap" - "^HeapScope::" YAML
Class Method Summary collapse
- .load!(path) ⇒ Object
- .load_yaml!(path) ⇒ Object
- .write_starter!(path = "heapscope.yml", force: false) ⇒ Object
Class Method Details
.load!(path) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/heapscope/config.rb', line 128 def load!(path) raise ConfigurationError, "Config not found: #{path}" unless File.exist?(path) case File.extname(path) when ".yml", ".yaml" load_yaml!(path) when ".rb" load(path) else raise ConfigurationError, "Unsupported config type: #{path}" end HeapScope.config end |
.load_yaml!(path) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/heapscope/config.rb', line 142 def load_yaml!(path) require "yaml" data = YAML.safe_load_file(path, permitted_classes: [Symbol], aliases: true) || {} data = data["heapscope"] || data[:heapscope] || data HeapScope.configure do |c| c.mode = data["mode"]&.to_sym if data["mode"] c.track_allocations = data["track_allocations"] unless data["track_allocations"].nil? c.max_graph_depth = data["max_graph_depth"] if data["max_graph_depth"] c.max_objects = data["max_objects"] if data["max_objects"] c.object_sample_rate = data["object_sample_rate"] if data["object_sample_rate"] Array(data["ignore_patterns"]).each { |p| c.ignore_patterns << Regexp.new(p) } c.min_retention_cycles = data.dig("retention", "min_cycles") if data.dig("retention", "min_cycles") c.detect_globals = data["detect_globals"] unless data["detect_globals"].nil? c.detect_closures = data["detect_closures"] unless data["detect_closures"].nil? c.detect_fibers = data["detect_fibers"] unless data["detect_fibers"].nil? c.apply_noise_defaults = data["apply_noise_defaults"] unless data["apply_noise_defaults"].nil? end end |
.write_starter!(path = "heapscope.yml", force: false) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/heapscope/config.rb', line 161 def write_starter!(path = "heapscope.yml", force: false) raise ConfigurationError, "Refusing to overwrite existing #{path}" if File.exist?(path) && !force File.write(path, STARTER_YAML) path end |