Class: SmartEnv::UriProxy

Inherits:
BasicObject
Extended by:
Forwardable
Defined in:
lib/smart_env/uri_proxy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_key, uri) ⇒ UriProxy

Returns a new instance of UriProxy.



15
16
17
18
19
20
21
22
# File 'lib/smart_env/uri_proxy.rb', line 15

def initialize(_key, uri)
  @original = uri
  @uri = ::URI.parse(uri)
  @params = ::CGI.parse(@uri.query.to_s)
  @params.each do |key, values|
    @params[key] = values.first if values.size == 1
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
# File 'lib/smart_env/uri_proxy.rb', line 34

def method_missing(method, *args, &block)
  @original.send(method, *args, &block) 
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/smart_env/uri_proxy.rb', line 11

def params
  @params
end

Class Method Details

.when(key, value) ⇒ Object

for SmartEnv



25
26
27
# File 'lib/smart_env/uri_proxy.rb', line 25

def self.when(key, value)
  value.match(/^\w+:\/\//) 
end

Instance Method Details

#base_uri(port = true) ⇒ Object



29
30
31
32
# File 'lib/smart_env/uri_proxy.rb', line 29

def base_uri(port = true)
  base = "#{@uri.scheme}://#{@uri.host}"
  port ? "#{base}:#{@uri.port}" : base
end