Class: Press::Compiler
- Inherits:
-
Object
- Object
- Press::Compiler
- Defined in:
- lib/source_press/press.rb
Overview
Reads settings.file_order line by line, evaluates whether the line is an “import” statement and appends the result to a temporary file. A header containing all of the necessary imports is then compiled with the contents in the tmp file.
The compiler should never load a file into memory in its entirety, the file should instead be read line by line as to save memory. This process is certainly slower, however, it is a good compromise, especially when loading large files.
Instance Attribute Summary collapse
-
#check_import ⇒ Object
Returns the value of attribute check_import.
-
#head ⇒ Object
Returns the value of attribute head.
-
#ln_ending ⇒ Object
Returns the value of attribute ln_ending.
-
#removed ⇒ Object
Returns the value of attribute removed.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#silent ⇒ Object
Returns the value of attribute silent.
-
#tmp_files ⇒ Object
Returns the value of attribute tmp_files.
Instance Method Summary collapse
-
#initialize(settings, silent = false) ⇒ Compiler
constructor
A new instance of Compiler.
-
#run ⇒ Object
Runs compiler.
Constructor Details
#initialize(settings, silent = false) ⇒ Compiler
Returns a new instance of Compiler.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/source_press/press.rb', line 136 def initialize(settings, silent = false) self.settings = settings self.silent = silent self.check_import = true self.head = [] self.removed = [] self.tmp_files = [] import_kwords_warning end |
Instance Attribute Details
#check_import ⇒ Object
Returns the value of attribute check_import.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def check_import @check_import end |
#head ⇒ Object
Returns the value of attribute head.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def head @head end |
#ln_ending ⇒ Object
Returns the value of attribute ln_ending.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def ln_ending @ln_ending end |
#removed ⇒ Object
Returns the value of attribute removed.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def removed @removed end |
#settings ⇒ Object
Returns the value of attribute settings.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def settings @settings end |
#silent ⇒ Object
Returns the value of attribute silent.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def silent @silent end |
#tmp_files ⇒ Object
Returns the value of attribute tmp_files.
128 129 130 |
# File 'lib/source_press/press.rb', line 128 def tmp_files @tmp_files end |
Instance Method Details
#run ⇒ Object
Runs compiler
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/source_press/press.rb', line 150 def run start = Time.now # Parse lines removing import statements count = parse_files out_name = settings.output # Delete (settings.ovr_output && File.exist?(out_name)) && File.delete(out_name) # Combine head with output and export compiled file final_out = make_file(out_name) compile_output(final_out) final_out.close silent || puts(compile_info(count, final_out, (Time.now - start) * 1000)) end |