Class: RequireHooks::Bootsnap::VersionedCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/require-hooks/mode/bootsnap.rb

Overview

Bootsnap 1.24+ compiler wrapper. Its namespace isolates transformed ISeqs without changing Bootsnap's process-wide cache directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler, version_hash) ⇒ VersionedCompiler

Returns a new instance of VersionedCompiler.



46
47
48
49
50
# File 'lib/require-hooks/mode/bootsnap.rb', line 46

def initialize(compiler, version_hash)
  @compiler = compiler
  @version_hash = version_hash
  @namespace = "#{compiler.namespace}-require-hooks-#{version_hash}"
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



44
45
46
# File 'lib/require-hooks/mode/bootsnap.rb', line 44

def namespace
  @namespace
end

#version_hashObject (readonly)

Returns the value of attribute version_hash.



44
45
46
# File 'lib/require-hooks/mode/bootsnap.rb', line 44

def version_hash
  @version_hash
end

Instance Method Details

#input_to_output(source, path, args) ⇒ Object



65
66
67
# File 'lib/require-hooks/mode/bootsnap.rb', line 65

def input_to_output(source, path, args)
  compile(RequireHooks.context_for(path), path, args) || @compiler.input_to_output(source, path, args)
end

#input_to_storage(source, path, *args) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/require-hooks/mode/bootsnap.rb', line 52

def input_to_storage(source, path, *args)
  iseq = compile(RequireHooks.context_for(path), path, nil)
  return @compiler.input_to_storage(source, path, *args) unless iseq

  iseq.to_binary
rescue SyntaxError, TypeError
  ::Bootsnap::CompileCache::UNCOMPILABLE
end

#storage_to_output(*args) ⇒ Object



61
62
63
# File 'lib/require-hooks/mode/bootsnap.rb', line 61

def storage_to_output(*args)
  @compiler.storage_to_output(*args)
end