Class: Yomikomu::BasicStorage
- Inherits:
-
Object
- Object
- Yomikomu::BasicStorage
show all
- Defined in:
- lib/yomikomu.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BasicStorage.
50
51
52
|
# File 'lib/yomikomu.rb', line 50
def initialize
require 'digest/sha1'
end
|
Instance Method Details
#compile_and_store_iseq(fname, iseq_key = iseq_key_name(fname = File.expand_path(fname))) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/yomikomu.rb', line 78
def compile_and_store_iseq fname, iseq_key = iseq_key_name(fname = File.expand_path(fname))
::Yomikomu.debug{ "compile #{fname} into #{iseq_key}" }
begin
iseq = RubyVM::InstructionSequence.compile_file(fname)
binary = iseq.to_binary((fname))
write_compiled_iseq(fname, iseq_key, binary)
::Yomikomu::STATISTICS[:compiled] += 1
iseq
rescue SyntaxError, RuntimeError => e
puts "#{e}: #{fname}"
nil
end
end
|
74
75
76
|
# File 'lib/yomikomu.rb', line 74
def fname
"SHA-1:#{::Digest::SHA1.file(fname).digest}"
end
|
#load_iseq(fname) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/yomikomu.rb', line 54
def load_iseq fname
iseq_key = iseq_key_name(fname)
if compiled_iseq_exist?(fname, iseq_key) && compiled_iseq_is_younger?(fname, iseq_key)
::Yomikomu::STATISTICS[:loaded] += 1
::Yomikomu.debug{ "load #{fname} from #{iseq_key}" }
binary = read_compiled_iseq(fname, iseq_key)
iseq = RubyVM::InstructionSequence.load_from_binary(binary)
iseq
elsif YOMIKOMU_AUTO_COMPILE
compile_and_store_iseq(fname, iseq_key)
else
::Yomikomu::STATISTICS[:ignored] += 1
::Yomikomu.debug{ "ignored #{fname}" }
nil
end
end
|