Class: SimpleConfig::Utilities::NetworkHost

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_config/utilities.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, port = nil, secure = false) ⇒ NetworkHost

Returns a new instance of NetworkHost.



8
9
10
11
# File 'lib/simple_config/utilities.rb', line 8

def initialize(name, port = nil, secure = false)
  @name, @port = name, port
  @secure = secure
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/simple_config/utilities.rb', line 6

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/simple_config/utilities.rb', line 6

def port
  @port
end

Class Method Details

.from_string(host_string) ⇒ Object



17
18
19
20
# File 'lib/simple_config/utilities.rb', line 17

def self.from_string(host_string)
  host, port = host_string.split(':')
  new(host, port.to_i)
end

Instance Method Details

#default_uri_schemeObject



35
36
37
# File 'lib/simple_config/utilities.rb', line 35

def default_uri_scheme
  secure? ? 'https' : 'http'
end

#secure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/simple_config/utilities.rb', line 13

def secure?
  @secure
end

#to_sObject



31
32
33
# File 'lib/simple_config/utilities.rb', line 31

def to_s
  [name, port].compact.join(':')
end

#to_uri(uri_options = {}) ⇒ Object



22
23
24
25
# File 'lib/simple_config/utilities.rb', line 22

def to_uri(uri_options = {})
  [:host, :port].each { |opt| uri_options.delete(opt) }
  URI::Generic.build({:host => name, :port => port, :scheme => default_uri_scheme}.merge(uri_options))
end

#url_for_path(path) ⇒ Object



27
28
29
# File 'lib/simple_config/utilities.rb', line 27

def url_for_path(path)
  to_uri(:path => path).to_s
end