Class: ReverseProxy::Bind::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/reverse_proxy/bind.rb

Direct Known Subclasses

Tcp, Unix

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Formatter

Returns a new instance of Formatter.



13
14
15
# File 'lib/reverse_proxy/bind.rb', line 13

def initialize data
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)



26
27
28
29
30
# File 'lib/reverse_proxy/bind.rb', line 26

def method_missing method
  return data.send method if data.respond_to? method
  return uri.send method  if %i{scheme host port path}.include? method
  format("#{method}".scan(/^to_([a-z]+)/)[0][0])
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/reverse_proxy/bind.rb', line 12

def data
  @data
end

Class Method Details

.add(type, format) ⇒ Object



5
6
7
# File 'lib/reverse_proxy/bind.rb', line 5

def add type, format
  formats[type.to_s] = format
end

.formatsObject



8
9
10
# File 'lib/reverse_proxy/bind.rb', line 8

def formats
  @@formats ||= {}
end

Instance Method Details

#to_sObject



19
20
21
# File 'lib/reverse_proxy/bind.rb', line 19

def to_s
  "#{self.class.name.split("::").last.underscore}://#{data}"
end

#uriObject



16
17
18
# File 'lib/reverse_proxy/bind.rb', line 16

def uri
  URI to_s
end