Class: Csv2Psql::JsonHelper
- Inherits:
-
Object
- Object
- Csv2Psql::JsonHelper
- Defined in:
- lib/csv2psql/helpers/json_helper.rb
Overview
Json Helper
Constant Summary collapse
- BASE_DIR =
File.join(File.dirname(__FILE__), '..')
Class Method Summary collapse
Class Method Details
.load_file(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/csv2psql/helpers/json_helper.rb', line 11 def load_file(path) # Load input file raw = IO.read(path) # Try to parse json from loaded data begin return MultiJson.load(raw) rescue Exception => e # rubocop:disable RescueException log_exception(e) raise e end nil end |
.log_exception(e) ⇒ Object
25 26 27 28 |
# File 'lib/csv2psql/helpers/json_helper.rb', line 25 def log_exception(e) puts 'Invalid json, see error.txt' File.open('error.txt', 'wt') { |f| f.write(e.to_s) } end |