lib/bootsnap/compile_cache/json.rb in bootsnap-1.9.4 vs lib/bootsnap/compile_cache/json.rb in bootsnap-1.10.0

- old
+ new

@@ -1,31 +1,37 @@ # frozen_string_literal: true -require('bootsnap/bootsnap') +require("bootsnap/bootsnap") + module Bootsnap module CompileCache module JSON class << self - attr_accessor(:msgpack_factory, :cache_dir, :supported_options) + attr_accessor(:msgpack_factory, :supported_options) + attr_reader(:cache_dir) + def cache_dir=(cache_dir) + @cache_dir = cache_dir.end_with?("/") ? "#{cache_dir}json" : "#{cache_dir}-json" + end + def input_to_storage(payload, _) obj = ::JSON.parse(payload) msgpack_factory.dump(obj) end def storage_to_output(data, kwargs) - if kwargs && kwargs.key?(:symbolize_names) + if kwargs&.key?(:symbolize_names) kwargs[:symbolize_keys] = kwargs.delete(:symbolize_names) end msgpack_factory.load(data, kwargs) end def input_to_output(data, kwargs) ::JSON.parse(data, **(kwargs || {})) end - def precompile(path, cache_dir: self.cache_dir) + def precompile(path) Bootsnap::CompileCache::Native.precompile( cache_dir, path.to_s, self, ) @@ -38,25 +44,26 @@ ::JSON.singleton_class.prepend(Patch) end end def init! - require('json') - require('msgpack') + require("json") + require("msgpack") self.msgpack_factory = MessagePack::Factory.new self.supported_options = [:symbolize_names] if ::JSON.parse('["foo"]', freeze: true).first.frozen? self.supported_options = [:freeze] end - self.supported_options.freeze + supported_options.freeze end end module Patch def load_file(path, *args) return super if args.size > 1 - if kwargs = args.first + + if (kwargs = args.first) return super unless kwargs.is_a?(Hash) return super unless (kwargs.keys - ::Bootsnap::CompileCache::JSON.supported_options).empty? end begin