Class: FakePin::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_pin/params.rb

Defined Under Namespace

Classes: MissingParametersError

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Params

Returns a new instance of Params.



12
13
14
# File 'lib/fake_pin/params.rb', line 12

def initialize(params)
  @params = params
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fake_pin/params.rb', line 16

def [](key)
  value = @params[key]
  if value.kind_of?(Hash)
    self.class.new(value)
  else
    value
  end
end

#require(*params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fake_pin/params.rb', line 25

def require(*params)
  missing_params = []
  params.each do |param|
    if param.kind_of?(Hash)
      parent_key = param.keys.first
      param[parent_key].each do |child_key|
        if @params[parent_key.to_s][child_key.to_s].nil?
          missing_params << child_key
        end
      end
    else
      if @params[param.to_s].nil?
        missing_params << param
      end
    end
  end

  if missing_params.length > 0
    raise MissingParametersError.new(missing_params)
  end
end