Module: Kernel
- Defined in:
- lib/shopifydev/pry/save_json.rb
Instance Method Summary collapse
Instance Method Details
#load_json(path = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/shopifydev/pry/save_json.rb', line 14 def load_json(path=nil) path = UnixTree.get_path(path, require: :file) if path puts Color.green{"loading json from #{path.to_s}..."} Oj.load(path) else nil end end |
#save_json(obj, path = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/shopifydev/pry/save_json.rb', line 2 def save_json(obj, path=nil) json = Oj.dump(obj, object:true, circular:true) path = UnixTree.get_path(path, require: :file, new: true) if path puts Color.green{"writing json to #{path.to_s}..."} File.open(path, 'w'){|f| f.write(json)} true else false end end |