Class: Dap::Input::InputJSON

Inherits:
Object
  • Object
show all
Includes:
FileSource
Defined in:
lib/dap/input.rb

Overview

JSON Input (line-delimited records)

Instance Attribute Summary

Attributes included from FileSource

#fd

Instance Method Summary collapse

Methods included from FileSource

#close, #open

Constructor Details

#initialize(args) ⇒ InputJSON

Returns a new instance of InputJSON.



57
58
59
# File 'lib/dap/input.rb', line 57

def initialize(args)
  self.open(args.first)
end

Instance Method Details

#read_recordObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dap/input.rb', line 61

def read_record
  line = self.fd.readline rescue nil
  return Error::EOF unless line
  begin
    json = Oj.load(line.strip, mode: :strict)
  rescue
    $stderr.puts "Record is not valid JSON and will be skipped: '#{line.chomp}'"
    return Error::InvalidFormat
  end
  return Error::Empty unless json
  json
end