Method: OpenC3::ConfigParser#parse_file

Defined in:
lib/openc3/config/config_parser.rb

#parse_file(filename, yield_non_keyword_lines = false, remove_quotes = true, run_erb = true, variables = {}) {|keyword, parameters| ... } ⇒ Object

Processes a file and yields |config| to the given block

Parameters:

  • filename (String)

    The full name and path of the configuration file

  • yield_non_keyword_lines (Boolean) (defaults to: false)

    Whether to yield all lines including blank lines or comment lines.

  • remove_quotes (Boolean) (defaults to: true)

    Whether to remove beginning and ending single or double quote characters from parameters.

  • run_erb (Boolean) (defaults to: true)

    Whether or not to run ERB on the file

  • variables (Hash) (defaults to: {})

    variables to pash to ERB context

  • block (Block)

    The block to yield to

Yield Parameters:

  • keyword (String)

    The keyword in the current parsed line

  • parameters (Array<String>)

    The parameters in the current parsed line

Raises:



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/openc3/config/config_parser.rb', line 197

def parse_file(filename,
               yield_non_keyword_lines = false,
               remove_quotes = true,
               run_erb = true,
               variables = {},
               &)
  raise Error.new(self, "Configuration file #{filename} does not exist.") unless filename && File.exist?(filename)

  @filename = filename

  # Create a temp file where we write the ERB parsed output
  file = create_parsed_output_file(filename, run_erb, variables)
  size = file.stat.size.to_f

  # Callbacks for beginning of parsing
  @@message_callback.call("Parsing #{size} bytes of #{filename}") if @@message_callback
  @@progress_callback.call(0.0) if @@progress_callback

  begin
    # Loop through each line of the data
    parse_loop(file,
               yield_non_keyword_lines,
               remove_quotes,
               size,
               PARSING_REGEX,
               &)
  ensure
    file.close unless file.closed?
  end
end