Class: Bootsnap::CLI
- Inherits:
-
Object
- Object
- Bootsnap::CLI
- Defined in:
- lib/bootsnap/cli.rb,
lib/bootsnap/cli/worker_pool.rb
Defined Under Namespace
Modules: RegexpMatchBackport Classes: WorkerPool
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#compile_gemfile ⇒ Object
Returns the value of attribute compile_gemfile.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#iseq ⇒ Object
Returns the value of attribute iseq.
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#yaml ⇒ Object
Returns the value of attribute yaml.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #list_files(path, pattern) ⇒ Object
- #precompile_command(*sources) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bootsnap/cli.rb', line 25 def initialize(argv) @argv = argv self.cache_dir = ENV.fetch("BOOTSNAP_CACHE_DIR", "tmp/cache") self.compile_gemfile = false self.exclude = nil self.verbose = false self.jobs = nil self.iseq = true self.yaml = true end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
21 22 23 |
# File 'lib/bootsnap/cli.rb', line 21 def argv @argv end |
#cache_dir ⇒ Object
Returns the value of attribute cache_dir.
21 22 23 |
# File 'lib/bootsnap/cli.rb', line 21 def cache_dir @cache_dir end |
#compile_gemfile ⇒ Object
Returns the value of attribute compile_gemfile.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def compile_gemfile @compile_gemfile end |
#exclude ⇒ Object
Returns the value of attribute exclude.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def exclude @exclude end |
#iseq ⇒ Object
Returns the value of attribute iseq.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def iseq @iseq end |
#jobs ⇒ Object
Returns the value of attribute jobs.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def jobs @jobs end |
#verbose ⇒ Object
Returns the value of attribute verbose.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def verbose @verbose end |
#yaml ⇒ Object
Returns the value of attribute yaml.
23 24 25 |
# File 'lib/bootsnap/cli.rb', line 23 def yaml @yaml end |
Instance Method Details
#list_files(path, pattern) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/bootsnap/cli.rb', line 86 def list_files(path, pattern) if File.directory?(path) Dir[File.join(path, pattern), sort: false] elsif File.exist?(path) [path] else [] end end |
#precompile_command(*sources) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 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/cli.rb', line 36 def precompile_command(*sources) require "bootsnap/compile_cache" fix_default_encoding do Bootsnap::CompileCache.setup( cache_dir: cache_dir, iseq: iseq, yaml: yaml, revalidation: true, ) @work_pool = WorkerPool.create(size: jobs, jobs: { ruby: method(:precompile_ruby), yaml: method(:precompile_yaml), }) @work_pool.spawn main_sources = sources.map { |d| File.(d) } precompile_ruby_files(main_sources) precompile_yaml_files(main_sources) if compile_gemfile # Gems that include JSON or YAML files usually don't put them in `lib/`. # So we look at the gem root. # Similarly, gems that include Rails engines generally file Ruby files in `app/`. # However some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling. gem_exclude = Regexp.union([exclude, "/spec/", "/test/", "/features/"].compact) gem_pattern = %r{^#{Regexp.escape(Bundler.bundle_path.to_s)}/?(?:bundler/)?gems/[^/]+} gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] || p }.uniq precompile_ruby_files(gem_paths, exclude: gem_exclude) precompile_yaml_files(gem_paths, exclude: gem_exclude) end if (exitstatus = @work_pool.shutdown) exit(exitstatus) end end 0 end |
#run ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/bootsnap/cli.rb', line 107 def run parser.parse!(argv) command = argv.shift method = "#{command}_command" if respond_to?(method) public_send(method, *argv) else invalid_usage!("Unknown command: #{command}") end end |