Class: GraphQL::Language::Printer::TruncatableBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/language/printer.rb

Defined Under Namespace

Classes: TruncateSizeReached

Constant Summary collapse

DEFAULT_INIT_CAPACITY =
500

Instance Method Summary collapse

Constructor Details

#initialize(truncate_size: nil) ⇒ TruncatableBuffer

Returns a new instance of TruncatableBuffer.



12
13
14
15
# File 'lib/graphql/language/printer.rb', line 12

def initialize(truncate_size: nil)
  @out = String.new(capacity: truncate_size || DEFAULT_INIT_CAPACITY)
  @truncate_size = truncate_size
end

Instance Method Details

#append(other) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/graphql/language/printer.rb', line 17

def append(other)
  if @truncate_size && (@out.size + other.size) > @truncate_size
    @out << other.slice(0, @truncate_size - @out.size)
    raise(TruncateSizeReached, "Truncate size reached")
  else
    @out << other
  end
end

#to_stringObject



26
27
28
# File 'lib/graphql/language/printer.rb', line 26

def to_string
  @out
end