Class: MongoHTTPSync::Parser::Handler

Inherits:
Oj::ScHandler
  • Object
show all
Defined in:
lib/mongo_http_sync/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Handler

Returns a new instance of Handler.



12
13
14
15
16
# File 'lib/mongo_http_sync/parser.rb', line 12

def initialize(block)
  @block = block
  @level = 0
  @ndocs = 0
end

Instance Attribute Details

#ndocsObject (readonly)

Returns the value of attribute ndocs.



11
12
13
# File 'lib/mongo_http_sync/parser.rb', line 11

def ndocs
  @ndocs
end

Instance Method Details

#array_append(a, v) ⇒ Object



41
42
43
# File 'lib/mongo_http_sync/parser.rb', line 41

def array_append(a,v)
  a << v
end

#array_startObject



37
38
39
# File 'lib/mongo_http_sync/parser.rb', line 37

def array_start
  []
end

#error(message, line, column) ⇒ Object



45
46
47
# File 'lib/mongo_http_sync/parser.rb', line 45

def error(message, line, column)
  throw "#{message} (line: #{line}, column: #{column})"
end

#hash_endObject



25
26
27
28
29
30
31
# File 'lib/mongo_http_sync/parser.rb', line 25

def hash_end
  @level -= 1
  if @level.zero?
    @block.call @root_hash if @level.zero?
    @ndocs += 1
  end
end

#hash_set(h, k, v) ⇒ Object



33
34
35
# File 'lib/mongo_http_sync/parser.rb', line 33

def hash_set(h,k,v)
  h[k.to_sym] = v
end

#hash_startObject



18
19
20
21
22
23
# File 'lib/mongo_http_sync/parser.rb', line 18

def hash_start
  @hash = {}
  @root_hash = @hash if @level.zero?
  @level += 1
  @hash
end