lib/tjson.rb in tjson-0.3.0 vs lib/tjson.rb in tjson-0.4.0

- old
+ new

@@ -1,11 +1,13 @@ # frozen_string_literal: true require "tjson/version" require "json" +require "set" require "time" + require "base32" require "base64" require "tjson/datatype" require "tjson/object" @@ -55,9 +57,22 @@ raise TJSON::ParseError, ex.message, ex.backtrace end raise TJSON::TypeError, "invalid toplevel type: #{object.class}" unless object.is_a?(TJSON::Object) object + end + + class << self + alias load parse + end + + # Load data from a file containing TJSON + # + # @param filename [String] name of the .tjson file + # @raise [TJSON::ParseError] an error occurred parsing the given file + # @return [Object] parsed data + def self.load_file(filename) + load(File.read(filename)) end # Generate TJSON from a Ruby Hash (TJSON only allows objects as toplevel values) # # @param obj [Hash] Ruby Hash to serialize as TJSON