Class: Prop::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/prop/options.rb

Class Method Summary collapse

Class Method Details

.build(options) ⇒ Object

Sanitizes the option set and sets defaults



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prop/options.rb', line 8

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] = get_strategy(result)

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

.get_strategy(options) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/prop/options.rb', line 25

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

.leaky_bucketObject



35
36
37
# File 'lib/prop/options.rb', line 35

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

.validate_options!(options) ⇒ Object



21
22
23
# File 'lib/prop/options.rb', line 21

def self.validate_options!(options)
  get_strategy(options).validate_options!(options)
end