Sha256: 4e5429b6f5e2915584c53fc6a47023eca88b788741826482aa090926f16f1021
Contents?: true
Size: 1.65 KB
Versions: 8
Compression:
Stored size: 1.65 KB
Contents
# Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html require 'sqreen/util' require 'sqreen/util/capped_hash' require 'sqreen/util/capped_string' require 'sqreen/util/capped_array' class Sqreen::Util::Capper attr_reader :string_size_cap, :size_cap, :depth_cap def initialize(opts = {}) string_size_cap = opts[:string_size_cap] || 4096 size_cap = opts[:size_cap] || 150 depth_cap = opts[:depth_cap] || 10 flat_size_cap = opts[:flat_size_cap] || 10000 @string_size_cap = string_size_cap @size_cap = size_cap @depth_cap = depth_cap @flat_size_cap = flat_size_cap end def call(e) r_call(e).first end private def r_call(e, opts = {}) size = opts[:size] || @flat_size_cap depth = opts[:depth] || @depth_cap case e when Hash h = Sqreen::Util::CappedHash.new(size_cap: size_cap, depth_cap: depth) e.each do |k, v| break unless size > 0 k_capped, = r_call(k, size: size, depth: depth - 1) v_capped, s = r_call(v, size: size, depth: depth - 1) size -= s h[k_capped] = v_capped end [h, h.size] when Array a = Sqreen::Util::CappedArray.new(size_cap: size_cap, depth_cap: depth) e.each do |v| break unless size > 0 c, s = r_call(v, size: size, depth: depth - 1) a << c size -= s end [a, a.size] when String return unless size > 0 size -= 1 s = Sqreen::Util::CappedString.new(size_cap: string_size_cap) << e [s, 1] else return unless size > 0 size -= 1 [e, 1] end end end
Version data entries
8 entries across 8 versions & 1 rubygems