Sha256: b711a46c6e623baebac23f73164aca8896fb352d4ab3e4b45a0d8c769c4082e0
Contents?: true
Size: 789 Bytes
Versions: 1
Compression:
Stored size: 789 Bytes
Contents
module DuckPuncher module JSONStorage require 'json' def self.dir_name Pathname.new('.duck_puncher') end def self.write(file_name, key, load_path) FileUtils.mkdir(dir_name) unless File.exist?(dir_name) data = read(file_name) key = key.to_sym data[key] ||= {} data[key][:require_with] ||= key.to_s.tr('-', '/') data[key][:load_paths] ||= [] data[key][:load_paths] << load_path.to_s unless data[key][:load_paths].include?(load_path.to_s) File.open(dir_name.join(file_name), 'wb') { |f| f << data.to_json } end def self.read(file_name) if File.exist?(dir_name.join file_name) JSON.parse File.read(dir_name.join file_name), symbolize_names: true else {} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
duck_puncher-5.0.1 | lib/duck_puncher/json_storage.rb |