Class: Groonga::Command::Parser::LoadValuesParser

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/command/parser/load-values-parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoadValuesParser

Returns a new instance of LoadValuesParser.



26
27
28
29
30
31
32
33
# File 'lib/groonga/command/parser/load-values-parser.rb', line 26

def initialize
  initialize_parser
  @on_value = nil
  @on_consumed = nil
  @on_end = nil
  @containers = []
  @keys = []
end

Instance Attribute Details

#on_consumed=(value) ⇒ Object (writeonly)

Sets the attribute on_consumed

Parameters:

  • value

    the value to set the attribute on_consumed to.



24
25
26
# File 'lib/groonga/command/parser/load-values-parser.rb', line 24

def on_consumed=(value)
  @on_consumed = value
end

#on_end=(value) ⇒ Object (writeonly)

Sets the attribute on_end

Parameters:

  • value

    the value to set the attribute on_end to.



25
26
27
# File 'lib/groonga/command/parser/load-values-parser.rb', line 25

def on_end=(value)
  @on_end = value
end

#on_value=(value) ⇒ Object (writeonly)

Sets the attribute on_value

Parameters:

  • value

    the value to set the attribute on_value to.



23
24
25
# File 'lib/groonga/command/parser/load-values-parser.rb', line 23

def on_value=(value)
  @on_value = value
end

Instance Method Details

#<<(data) ⇒ Object



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
71
72
# File 'lib/groonga/command/parser/load-values-parser.rb', line 35

def <<(data)
  data_size = data.bytesize
  return self if data_size.zero?

  before_pos = @parser.pos
  status = catch do |tag|
    @tag = tag
    begin
      @parser << data
    rescue JSON::Stream::ParserError => error
      pos = @parser.pos
      consumed = pos - before_pos - 1
      raise Error.new(error.message,
                      data[0, consumed],
                      data[consumed..-1])
    end
    :continue
  end

  pos = @parser.pos
  consumed = pos - before_pos
  if consumed > 0
    if consumed < data_size
      @on_consumed.call(data[0, consumed])
    else
      @on_consumed.call(data)
    end
  end
  if status == :done
    if consumed < data_size
      @on_end.call(data[consumed..-1])
    else
      @on_end.call(nil)
    end
  end

  self
end