# 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/log/loggable' require 'sqreen/weave' class Sqreen::Weave::Budget include Sqreen::Log::Loggable def initialize(threshold, ratio = nil) @threshold = threshold @ratio = ratio end def static? threshold && !ratio end def dynamic? threshold && ratio end attr_reader :threshold attr_reader :ratio def to_h { threshold: threshold, ratio: ratio } end class << self attr_reader :current def update(opts = nil) Sqreen::Weave.logger.info("budget update:#{opts.inspect}") return @current = nil if opts.nil? || opts.empty? threshold = opts[:threshold] ratio = opts[:ratio] @current = new(threshold, ratio) end end end