Sha256: bb7f2dbd4496ecab9fb725f8678815d263903225f280db993a73997584001ef2

Contents?: true

Size: 600 Bytes

Versions: 29

Compression:

Stored size: 600 Bytes

Contents

# typed: false

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/util'

class Sqreen::Util::CappedString < String
  attr_reader :size_cap

  def initialize(*args, &block)
    opts = args.last.is_a?(Hash) ? args.pop : {}
    size_cap = opts[:size_cap] || 4096
    @size_cap = size_cap
    super(*args, &block)
  end

  def <<(value)
    return self unless size < size_cap

    value = value[0, size_cap - size] if size + value.size > size_cap

    super(value)
  end
  alias_method :concat, :<<
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sqreen-1.22.0-java lib/sqreen/util/capped_string.rb
sqreen-1.22.0 lib/sqreen/util/capped_string.rb
sqreen-1.21.1-java lib/sqreen/util/capped_string.rb
sqreen-1.21.1 lib/sqreen/util/capped_string.rb
sqreen-1.21.0-java lib/sqreen/util/capped_string.rb
sqreen-1.21.0 lib/sqreen/util/capped_string.rb
sqreen-1.20.4-java lib/sqreen/util/capped_string.rb
sqreen-1.20.4 lib/sqreen/util/capped_string.rb
sqreen-1.21.0.beta3-java lib/sqreen/util/capped_string.rb
sqreen-1.21.0.beta3 lib/sqreen/util/capped_string.rb
sqreen-1.20.4.beta1 lib/sqreen/util/capped_string.rb
sqreen-1.19.4 lib/sqreen/util/capped_string.rb
sqreen-1.20.3 lib/sqreen/util/capped_string.rb
sqreen-1.20.2 lib/sqreen/util/capped_string.rb
sqreen-1.21.0.beta2 lib/sqreen/util/capped_string.rb
sqreen-1.21.0.beta1 lib/sqreen/util/capped_string.rb
sqreen-1.20.1-java lib/sqreen/util/capped_string.rb
sqreen-1.20.1 lib/sqreen/util/capped_string.rb
sqreen-1.20.0-java lib/sqreen/util/capped_string.rb
sqreen-1.20.0 lib/sqreen/util/capped_string.rb