From c3614877d205e716bc94ad521918ad57c12ed445 Mon Sep 17 00:00:00 2001 From: Keith Bennett Date: Tue, 30 Jun 2020 14:07:23 -0400 Subject: [flori/json] Add `load_file` and `load_file!` methods, with tests. Fixes issue #386. https://github.com/flori/json/commit/0be363c99b --- ext/json/lib/json/common.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ext/json/lib') diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index 8e45b511fc..bf2c599d0d 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -282,6 +282,16 @@ module JSON Parser.new(source, **(opts||{})).parse end + # Parses the content of a file (see parse method documentation for more information). + def load_file(filespec, opts = {}) + parse(File.read(filespec), opts) + end + + # Parses the content of a file (see parse! method documentation for more information). + def load_file!(filespec, opts = {}) + parse!(File.read(filespec), opts) + end + # :call-seq: # JSON.generate(obj, opts = nil) -> new_string # -- cgit v1.2.3