Class: BEL::JSON::StreamHandler

Inherits:
Oj::ScHandler
  • Object
show all
Defined in:
lib/bel/json/adapter/oj.rb

Instance Method Summary collapse

Constructor Details

#initialize(callable) ⇒ StreamHandler

Returns a new instance of StreamHandler.



69
70
71
# File 'lib/bel/json/adapter/oj.rb', line 69

def initialize(callable)
  @callable = callable
end

Instance Method Details

#array_append(array, value) ⇒ Object



91
92
93
94
# File 'lib/bel/json/adapter/oj.rb', line 91

def array_append(array, value)
  array << value
  @array = array
end

#array_endObject



96
97
98
# File 'lib/bel/json/adapter/oj.rb', line 96

def array_end()
  @callable.call @array
end

#array_startObject



86
87
88
89
# File 'lib/bel/json/adapter/oj.rb', line 86

def array_start
  @array = []
  @array
end

#error(message, line, column) ⇒ Object

Raises:

  • (Oj::ParseError)


100
101
102
103
# File 'lib/bel/json/adapter/oj.rb', line 100

def error(message, line, column)
  msg = "Parse error at line #{line}, column #{column}: #{message}"
  raise Oj::ParseError.new(msg)
end

#hash_endObject



77
78
79
# File 'lib/bel/json/adapter/oj.rb', line 77

def hash_end
  @callable.call @hash 
end

#hash_set(hash, key, value) ⇒ Object



81
82
83
84
# File 'lib/bel/json/adapter/oj.rb', line 81

def hash_set(hash, key, value)
  hash[key]  = value
  @hash = hash
end

#hash_startObject



73
74
75
# File 'lib/bel/json/adapter/oj.rb', line 73

def hash_start
  {}
end