Class: SmlFile
- Inherits:
-
Object
show all
- Defined in:
- lib/sml_file.rb
Defined Under Namespace
Classes: CannotCompile, NotCompiled, NotSaved
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path, contents = nil) ⇒ SmlFile
10
11
12
13
|
# File 'lib/sml_file.rb', line 10
def initialize(path, contents=nil)
@path = path
@contents = contents || File.read(@path)
end
|
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
8
9
10
|
# File 'lib/sml_file.rb', line 8
def contents
@contents
end
|
#path ⇒ Object
Returns the value of attribute path.
8
9
10
|
# File 'lib/sml_file.rb', line 8
def path
@path
end
|
Instance Method Details
#compile!(destination) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sml_file.rb', line 26
def compile!(destination)
raise NotSaved unless @path
@exe_path = destination
output = `mosmlc #{@path} -o #{@exe_path}`
unless output.empty?
raise CannotCompile, output
end
end
|
#delete! ⇒ Object
46
47
48
49
|
# File 'lib/sml_file.rb', line 46
def delete!
FileUtils.rm_f(@path)
@path = nil
end
|
#prepare_tests ⇒ Object
21
22
23
24
|
# File 'lib/sml_file.rb', line 21
def prepare_tests
formatted_content = FormatsTests.format(FormatsLines.format(@contents))
self.class.new(nil, formatted_content)
end
|
#run ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/sml_file.rb', line 38
def run
if @exe_path
`./#{@exe_path}`
else
raise NotCompiled
end
end
|
#save_as!(new_path) ⇒ Object
15
16
17
18
19
|
# File 'lib/sml_file.rb', line 15
def save_as!(new_path)
if File.write(new_path, @contents)
@path = new_path
end
end
|