Sha256: bd76d507f494753130bf7d5cbf757614bf849dfd715b20bd0d9e46773aa13b56
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
module Vernacular # Represents a file that contains Ruby source code that can be read from and # compiled down to instruction sequences. class SourceFile attr_reader :source_path, :iseq_path def initialize(source_path, iseq_path) @source_path = source_path @iseq_path = iseq_path end def dump source = Vernacular.modify(File.read(source_path)) iseq = RubyVM::InstructionSequence.compile(source, source_path, source_path) digest = ::Digest::MD5.file(source_path).digest File.binwrite(iseq_path, iseq.to_binary("MD5:#{digest}")) iseq rescue SyntaxError, RuntimeError nil end def load if File.exist?(iseq_path) && (File.mtime(source_path) <= File.mtime(iseq_path)) RubyVM::InstructionSequence.load_from_binary(File.binread(iseq_path)) else dump end end def self.load_iseq(source_path) new( source_path, File.join(Vernacular.iseq_dir, Vernacular.iseq_path_for(source_path)) ).load end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vernacular-0.1.2 | lib/vernacular/source_file.rb |
vernacular-0.1.1 | lib/vernacular/source_file.rb |
vernacular-0.1.0 | lib/vernacular/source_file.rb |