Class: Threatinator::Parsers::JSON::Parser
- Inherits:
-
Threatinator::Parser
- Object
- Threatinator::Parser
- Threatinator::Parsers::JSON::Parser
- Defined in:
- lib/threatinator/parsers/json/parser.rb
Class Method Summary collapse
-
.adapter_class ⇒ Object
Detects the platform, loads the JSON adapter, and returns the adapter’s class.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(opts = {}) ⇒ Parser
constructor
A new instance of Parser.
- #run(io) {|record| ... } ⇒ Object
Methods inherited from Threatinator::Parser
Constructor Details
#initialize(opts = {}) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 |
# File 'lib/threatinator/parsers/json/parser.rb', line 8 def initialize(opts = {}) @adapter_class = self.class.adapter_class super(opts) end |
Class Method Details
.adapter_class ⇒ Object
Detects the platform, loads the JSON adapter, and returns the adapter’s class.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/threatinator/parsers/json/parser.rb', line 15 def self.adapter_class if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' #:nocov: raise "JSON parsing not supported for JRuby" #:nocov: else require 'threatinator/parsers/json/adapters/oj' return Threatinator::Parsers::JSON::Adapters::Oj end end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/threatinator/parsers/json/parser.rb', line 26 def ==(other) super(other) end |
#run(io) {|record| ... } ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/threatinator/parsers/json/parser.rb', line 33 def run(io) adapter = @adapter_class.new callback = lambda do |object, opts = {}| yield Threatinator::Parsers::JSON::Record.new(object, opts) end adapter.run(io, &callback) nil end |