Module: Bootsnap
- Extended by:
- Bootsnap
- Included in:
- Bootsnap
- Defined in:
- lib/bootsnap.rb,
lib/bootsnap/cli.rb,
lib/bootsnap/bundler.rb,
lib/bootsnap/version.rb,
lib/bootsnap/compile_cache.rb,
lib/bootsnap/cli/worker_pool.rb,
lib/bootsnap/load_path_cache.rb,
lib/bootsnap/explicit_require.rb,
lib/bootsnap/compile_cache/iseq.rb,
lib/bootsnap/compile_cache/json.rb,
lib/bootsnap/compile_cache/yaml.rb,
lib/bootsnap/load_path_cache/path.rb,
lib/bootsnap/load_path_cache/cache.rb,
lib/bootsnap/load_path_cache/store.rb,
lib/bootsnap/load_path_cache/path_scanner.rb,
lib/bootsnap/load_path_cache/change_observer.rb,
lib/bootsnap/load_path_cache/loaded_features_index.rb,
ext/bootsnap/bootsnap.c
Defined Under Namespace
Modules: CompileCache, ExplicitRequire, LoadPathCache Classes: CLI
Constant Summary collapse
- InvalidConfiguration =
Class.new(StandardError)
- VERSION =
"1.18.4"
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- ._instrument(event, path) ⇒ Object
- .default_setup ⇒ Object
- .instrumentation=(callback) ⇒ Object
-
.instrumentation_enabled= ⇒ Object
Functions exposed as module functions on Bootsnap::CompileCache::Native.
- .log! ⇒ Object
- .log_stats! ⇒ Object
- .setup(cache_dir:, development_mode: true, load_path_cache: true, ignore_directories: nil, readonly: false, revalidation: false, compile_cache_iseq: true, compile_cache_yaml: true, compile_cache_json: true) ⇒ Object
- .unload_cache! ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/bootsnap.rb', line 12 def logger @logger end |
Class Method Details
._instrument(event, path) ⇒ Object
44 45 46 |
# File 'lib/bootsnap.rb', line 44 def _instrument(event, path) @instrumentation.call(event, path) end |
.default_setup ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 |
# File 'lib/bootsnap.rb', line 82 def default_setup env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["ENV"] development_mode = ["", nil, "development"].include?(env) if enabled?("BOOTSNAP") cache_dir = ENV["BOOTSNAP_CACHE_DIR"] unless cache_dir config_dir_frame = caller.detect do |line| line.include?("/config/") end unless config_dir_frame $stderr.puts("[bootsnap/setup] couldn't infer cache directory! Either:") $stderr.puts("[bootsnap/setup] 1. require bootsnap/setup from your application's config directory; or") $stderr.puts("[bootsnap/setup] 2. Define the environment variable BOOTSNAP_CACHE_DIR") raise("couldn't infer bootsnap cache directory") end path = config_dir_frame.split(/:\d+:/).first path = File.dirname(path) until File.basename(path) == "config" app_root = File.dirname(path) cache_dir = File.join(app_root, "tmp", "cache") end ignore_directories = if ENV.key?("BOOTSNAP_IGNORE_DIRECTORIES") ENV["BOOTSNAP_IGNORE_DIRECTORIES"].split(",") end setup( cache_dir: cache_dir, development_mode: development_mode, load_path_cache: enabled?("BOOTSNAP_LOAD_PATH_CACHE"), compile_cache_iseq: enabled?("BOOTSNAP_COMPILE_CACHE"), compile_cache_yaml: enabled?("BOOTSNAP_COMPILE_CACHE"), compile_cache_json: enabled?("BOOTSNAP_COMPILE_CACHE"), readonly: bool_env("BOOTSNAP_READONLY"), revalidation: bool_env("BOOTSNAP_REVALIDATE"), ignore_directories: ignore_directories, ) if ENV["BOOTSNAP_LOG"] log! elsif ENV["BOOTSNAP_STATS"] log_stats! end end end |
.instrumentation=(callback) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/bootsnap.rb', line 37 def instrumentation=(callback) @instrumentation = callback if respond_to?(:instrumentation_enabled=, true) self.instrumentation_enabled = !!callback end end |
.instrumentation_enabled= ⇒ Object
Functions exposed as module functions on Bootsnap::CompileCache::Native
110 |
# File 'ext/bootsnap/bootsnap.c', line 110
static VALUE bs_instrumentation_enabled_set(VALUE self, VALUE enabled);
|
.log! ⇒ Object
24 25 26 |
# File 'lib/bootsnap.rb', line 24 def log! self.logger = $stderr.method(:puts) end |
.log_stats! ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/bootsnap.rb', line 14 def log_stats! stats = {hit: 0, revalidated: 0, miss: 0, stale: 0} self.instrumentation = ->(event, _path) { stats[event] += 1 } Kernel.at_exit do stats.each do |event, count| $stderr.puts "bootsnap #{event}: #{count}" end end end |
.setup(cache_dir:, development_mode: true, load_path_cache: true, ignore_directories: nil, readonly: false, revalidation: false, compile_cache_iseq: true, compile_cache_yaml: true, compile_cache_json: true) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bootsnap.rb', line 48 def setup( cache_dir:, development_mode: true, load_path_cache: true, ignore_directories: nil, readonly: false, revalidation: false, compile_cache_iseq: true, compile_cache_yaml: true, compile_cache_json: true ) if load_path_cache Bootsnap::LoadPathCache.setup( cache_path: "#{cache_dir}/bootsnap/load-path-cache", development_mode: development_mode, ignore_directories: ignore_directories, readonly: readonly, ) end Bootsnap::CompileCache.setup( cache_dir: "#{cache_dir}/bootsnap/compile-cache", iseq: compile_cache_iseq, yaml: compile_cache_yaml, json: compile_cache_json, readonly: readonly, revalidation: revalidation, ) end |
.unload_cache! ⇒ Object
78 79 80 |
# File 'lib/bootsnap.rb', line 78 def unload_cache! LoadPathCache.unload! end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
133 134 135 |
# File 'lib/bootsnap.rb', line 133 def absolute_path?(path) path[1] == ":" end |
#bundler? ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bootsnap/bundler.rb', line 6 def bundler? return false unless defined?(::Bundler) # Bundler environment variable %w(BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |current| return true if ENV.key?(current) end false end |