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.



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

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.



11
12
13
# File 'lib/simple_config/utilities.rb', line 11

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/simple_config/utilities.rb', line 11

def port
  @port
end

Class Method Details

.from_string(host_string) ⇒ Object



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

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

Instance Method Details

#default_uri_schemeObject



40
41
42
# File 'lib/simple_config/utilities.rb', line 40

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

#secure?Boolean

Returns:

  • (Boolean)


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

def secure?
  @secure
end

#to_sObject



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

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

#to_uri(uri_options = {}) ⇒ Object



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

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



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

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