Method: NestedText.load_file

Defined in:
lib/nestedtext/decode.rb

.load_file(filename, top_class: Object, strict: false) ⇒ Object?

Decode a NestedText stored in a given file.

Raises:

  • (NestedText::Error)

    if anything went wrong.

  • (IOError)

    on issue opening filename for reading in text mode.



34
35
36
37
38
39
40
41
# File 'lib/nestedtext/decode.rb', line 34

def self.load_file(filename, top_class: Object, strict: false)
  raise Errors::WrongInputTypeError.new([String], filename) unless !filename.nil? && filename.is_a?(String)

  # Open explicitly in text mode to detect \r as line ending.
  File.open(filename, 'rt') do |file|
    Parser.new(file, top_class, strict: strict).parse
  end
end