Sha256: addc2f1633c65779f2d7d7e2fa64e52df6ad79f8292781fee7874630b2950826
Contents?: true
Size: 779 Bytes
Versions: 29
Compression:
Stored size: 779 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::CappedArray < Array attr_reader :size_cap, :depth_cap def initialize(*args, &block) opts = args.last.is_a?(Hash) ? args.pop : {} size_cap = opts[:size_cap] || 150 depth_cap = opts[:depth_cap] || 10 @size_cap = size_cap @depth_cap = depth_cap super(*args, &block) end def <<(value) keep?(size, value) ? super : self end alias_method :append, :<< def []=(index, value) super if keep?(index, value) end private def keep?(index, value) index < size_cap && (depth_cap > 0 || !value.is_a?(Hash) && !value.is_a?(Array)) end end
Version data entries
29 entries across 29 versions & 1 rubygems