-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
schandler.rb
70 lines (61 loc) · 1.59 KB
/
schandler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Oj
# A Simple Callback Parser (SCP) for JSON. The Oj::ScHandler class should be
# subclassed and then used with the Oj.sc_parse() method. The Scp methods will
# then be called as the file is parsed. The handler does not have to be a
# subclass of the ScHandler class as long as it responds to the desired
# methods.
#
# @example
#
# require 'oj'
#
# class MyHandler < ::Oj::ScHandler
# def initialize()
# @hash_cnt = 0
# end
#
# def hash_start()
# @hash_cnt += 1
# end
# end
#
# cnt = MyHandler.new()
# File.open('any.json', 'r') do |f|
# Oj.sc_parse(cnt, f)
# end
#
# To make the desired methods active while parsing the desired method should
# be made public in the subclasses. If the methods remain private they will
# not be called during parsing.
#
# def hash_start(); end
# def hash_end(); end
# def array_start(); end
# def array_end(); end
# def add_value(value); end
# def error(message, line, column); end
#
class ScHandler
# Create a new instance of the ScHandler class.
def initialize()
end
# To make the desired methods active while parsing the desired method should
# be made public in the subclasses. If the methods remain private they will
# not be called during parsing.
private
def hash_start()
end
def hash_end()
end
def array_start()
end
def array_end()
end
def add_value(value)
end
def hash_set(h, key, value)
end
def array_append(a, value)
end
end # ScHandler
end # Oj