Class: Press::Compiler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_importObject

Returns the value of attribute check_import.



128
129
130
# File 'lib/source_press/press.rb', line 128

def check_import
  @check_import
end

#headObject

Returns the value of attribute head.



128
129
130
# File 'lib/source_press/press.rb', line 128

def head
  @head
end

#ln_endingObject

Returns the value of attribute ln_ending.



128
129
130
# File 'lib/source_press/press.rb', line 128

def ln_ending
  @ln_ending
end

#removedObject

Returns the value of attribute removed.



128
129
130
# File 'lib/source_press/press.rb', line 128

def removed
  @removed
end

#settingsObject

Returns the value of attribute settings.



128
129
130
# File 'lib/source_press/press.rb', line 128

def settings
  @settings
end

#silentObject

Returns the value of attribute silent.



128
129
130
# File 'lib/source_press/press.rb', line 128

def silent
  @silent
end

#tmp_filesObject

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

#runObject

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