Class: SimpleConfig::Utilities::NetworkHost
- Inherits:
-
Object
- Object
- SimpleConfig::Utilities::NetworkHost
- Defined in:
- lib/simple_config/utilities.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #default_uri_scheme ⇒ Object
-
#initialize(name, port = nil, secure = false) ⇒ NetworkHost
constructor
A new instance of NetworkHost.
- #secure? ⇒ Boolean
- #to_s ⇒ Object
- #to_uri(uri_options = {}) ⇒ Object
- #url_for_path(path) ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/simple_config/utilities.rb', line 11 def name @name end |
#port ⇒ Object (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_scheme ⇒ Object
40 41 42 |
# File 'lib/simple_config/utilities.rb', line 40 def default_uri_scheme secure? ? 'https' : 'http' end |
#secure? ⇒ Boolean
18 19 20 |
# File 'lib/simple_config/utilities.rb', line 18 def secure? @secure end |
#to_s ⇒ Object
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( = {}) [:host, :port].each { |opt| .delete(opt) } URI::Generic.build({:host => name, :port => port, :scheme => default_uri_scheme}.merge()) 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 |