Class: 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.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/simple_config/utilities.rb', line 6 def name @name end |
#port ⇒ Object (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_scheme ⇒ Object
35 36 37 |
# File 'lib/simple_config/utilities.rb', line 35 def default_uri_scheme secure? ? 'https' : 'http' end |
#secure? ⇒ Boolean
13 14 15 |
# File 'lib/simple_config/utilities.rb', line 13 def secure? @secure end |
#to_s ⇒ Object
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( = {}) [:host, :port].each { |opt| .delete(opt) } URI::Generic.build({:host => name, :port => port, :scheme => default_uri_scheme}.merge()) 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 |