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

Raises:

  • (RuntimeError)


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

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[:threshold] = result[:threshold].to_i
  result[:interval]  = result[:interval].to_i

  raise RuntimeError.new("Invalid threshold setting") unless result[:threshold] > 0
  raise RuntimeError.new("Invalid interval setting")  unless result[:interval] > 0

  result
end