Sha256: a1f36eaedfd5acc7fb12fb21371aeef459ffdb32ee2b0e50e7353f10a03c715a

Contents?: true

Size: 784 Bytes

Versions: 6

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true
require 'prop/key'

module Prop
  class Options

    # Sanitizes the option set and sets defaults
    def self.build(options)
      key      = options.fetch(:key)
      params   = options.fetch(:params)
      defaults = options.fetch(:defaults)
      result   = defaults.merge(params)

      result[:key] = Prop::Key.normalize(key)

      result[:strategy] = if leaky_bucket.include?(result[:strategy])
        Prop::LeakyBucketStrategy
      elsif result[:strategy] == nil
        Prop::IntervalStrategy
      else
        result[:strategy] # allowing any new/unknown strategy to be used
      end

      result[:strategy].validate_options!(result)
      result
    end

    def self.leaky_bucket
      [:leaky_bucket, "leaky_bucket"]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
prop-2.3.0 lib/prop/options.rb
prop-2.2.5 lib/prop/options.rb
prop-2.2.4 lib/prop/options.rb
prop-2.2.2 lib/prop/options.rb
prop-2.2.1 lib/prop/options.rb
prop-2.2.0 lib/prop/options.rb