Module: ASTTransform::InstructionSequence
- Defined in:
- lib/ast_transform/instruction_sequence.rb,
lib/ast_transform/instruction_sequence/mixin.rb,
lib/ast_transform/instruction_sequence/bootsnap_mixin.rb
Defined Under Namespace
Modules: BootsnapMixin, Mixin
Class Method Summary
collapse
Class Method Details
12
13
14
15
16
17
18
19
20
|
# File 'lib/ast_transform/instruction_sequence.rb', line 12
def source_to_transformed_iseq(source, source_path)
transformer = ASTTransform::Transformer.new(ASTTransform::Transformation.new)
rewritten_file_pathname = write_pathname(source_path)
rewritten_source = transformer.transform_file_source(source, source_path, rewritten_file_pathname.to_s)
write(rewritten_source, rewritten_file_pathname)
RubyVM::InstructionSequence.compile(rewritten_source, rewritten_file_pathname.to_s, rewritten_file_pathname.to_s)
end
|
.using_bootsnap_compilation? ⇒ Boolean
5
6
7
8
9
10
|
# File 'lib/ast_transform/instruction_sequence.rb', line 5
def using_bootsnap_compilation?
filepath, = RubyVM::InstructionSequence.method(:load_iseq).source_location
filepath =~ %r{/bootsnap/}
rescue NameError
false
end
|
.write(string, pathname) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/ast_transform/instruction_sequence.rb', line 28
def write(string, pathname)
FileUtils.mkdir_p(pathname.dirname)
File.open(pathname, 'w') do |file|
file.write(string)
end
end
|
.write_pathname(file_path) ⇒ Object
22
23
24
25
26
|
# File 'lib/ast_transform/instruction_sequence.rb', line 22
def write_pathname(file_path)
project_path = File.expand_path("")
relative_source_file_pathname = Pathname.new(file_path).relative_path_from(Pathname.new(project_path))
Pathname.new("").join(project_path, 'tmp', 'ast_transform', relative_source_file_pathname)
end
|