Class: MoCo::Compiler
- Inherits:
-
Object
show all
- Defined in:
- lib/moco/compiler.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source_file, compiled_file = nil, compiled_dir = nil) ⇒ Compiler
Returns a new instance of Compiler.
34
35
36
37
38
39
|
# File 'lib/moco/compiler.rb', line 34
def initialize(source_file, compiled_file = nil, compiled_dir = nil)
@source_file = source_file
@compiled_file = compiled_file || compiled_filename(compiled_dir)
validate_filenames
require_libraries
end
|
Instance Attribute Details
#compiled_file ⇒ Object
Returns the value of attribute compiled_file.
32
33
34
|
# File 'lib/moco/compiler.rb', line 32
def compiled_file
@compiled_file
end
|
#source_file ⇒ Object
Returns the value of attribute source_file.
31
32
33
|
# File 'lib/moco/compiler.rb', line 31
def source_file
@source_file
end
|
Class Method Details
.compiled_extension ⇒ Object
27
28
29
|
# File 'lib/moco/compiler.rb', line 27
def self.compiled_extension
raise NotImplementedError
end
|
.convert_option(key, value) ⇒ Object
23
24
25
|
# File 'lib/moco/compiler.rb', line 23
def self.convert_option(key, value)
[key.to_sym, CompilerOption.convert(value)]
end
|
.options ⇒ Object
19
20
21
|
# File 'lib/moco/compiler.rb', line 19
def self.options
(@options || {}).dup
end
|
.register(source_extension) ⇒ Object
5
6
7
|
# File 'lib/moco/compiler.rb', line 5
def self.register(source_extension)
MoCo.register(self, source_extension)
end
|
.require_library(lib, gem_name = lib, version = nil) ⇒ Object
9
10
11
12
|
# File 'lib/moco/compiler.rb', line 9
def self.require_library(lib, gem_name = lib, version = nil)
@libraries ||= []
@libraries << [lib, gem_name, version]
end
|
.set_option(key, value = true) ⇒ Object
14
15
16
17
|
# File 'lib/moco/compiler.rb', line 14
def self.set_option(key, value = true)
@options ||= {}
@options[key] = value
end
|
Instance Method Details
#compile ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/moco/compiler.rb', line 45
def compile
write_compiled(compiled_text)
rescue SyntaxError, StandardError => e
error = CompileError.new(e, @source_file)
error.set_backtrace(e.backtrace)
write_compiled(error_text(error))
raise error
end
|
#compiled_text ⇒ Object
62
63
64
|
# File 'lib/moco/compiler.rb', line 62
def compiled_text
raise NotImplementedError
end
|
#options ⇒ Object
54
55
56
|
# File 'lib/moco/compiler.rb', line 54
def options
self.class.options
end
|
#should_compile? ⇒ Boolean
41
42
43
|
# File 'lib/moco/compiler.rb', line 41
def should_compile?
! FileUtil.up_to_date?(@compiled_file, @source_file)
end
|
#source_text ⇒ Object
58
59
60
|
# File 'lib/moco/compiler.rb', line 58
def source_text
File.read(@source_file)
end
|