Class: BooticClient::WhinyURI

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_client/whiny_uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href, complain_on_undeclared_params = true) ⇒ WhinyURI

Returns a new instance of WhinyURI.


9
10
11
12
13
14
# File 'lib/bootic_client/whiny_uri.rb', line 9

def initialize(href, complain_on_undeclared_params = true)
  @href = href
  @uri = URITemplate.new(href)
  @variables = @uri.variables
  @complain_on_undeclared_params = complain_on_undeclared_params
end

Instance Attribute Details

#variablesObject (readonly)

Returns the value of attribute variables.


7
8
9
# File 'lib/bootic_client/whiny_uri.rb', line 7

def variables
  @variables
end

Instance Method Details

#expand(attrs = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bootic_client/whiny_uri.rb', line 16

def expand(attrs = {})
  attrs = stringify(attrs)

  missing = missing_path_variables(attrs)
  if missing.any?
    raise InvalidURLError, missing_err(missing)
  end

  undeclared = undeclared_params(attrs)
  if complain_on_undeclared_params
    if undeclared.any?
      raise InvalidURLError, undeclared_err(undeclared)
    end
  end

  uri.expand whitelisted(attrs)
end