Class: Vermillion::Helper::Endpoint
- Inherits:
-
Object
- Object
- Vermillion::Helper::Endpoint
- Defined in:
- lib/client/helper/endpoint.rb
Instance Attribute Summary collapse
-
#server ⇒ Object
writeonly
Set the @server variable externally.
Instance Method Summary collapse
-
#add(key, value) ⇒ Object
- Add a section to the path Params:
key
- Symbol, the key to identify the section
value
-
Any value to store with the associated key.
- Symbol, the key to identify the section
- Add a section to the path Params:
-
#delete(key) ⇒ Object
- Deletes a value from the internal hash based on a key Params:
key
-
Symbol, the key to identify the section.
- Deletes a value from the internal hash based on a key Params:
-
#exists?(key) ⇒ Boolean
- Checks whether a key exists Params:
key
-
Symbol, the key to identify the section.
- Checks whether a key exists Params:
-
#get(key) ⇒ Object
- Return a value based on the provided key Params:
key
-
Symbol, the key to identify the section.
- Return a value based on the provided key Params:
-
#initialize(initial_path) ⇒ Endpoint
constructor
- Creates the Endpoint object with default values for internal variables Params:
initial_path
-
Starting point of the URL this class will build.
- Creates the Endpoint object with default values for internal variables Params:
-
#protocol=(use_https) ⇒ Object
- Set endpoint protocol Params:
use_https
-
Boolean value for whether to use HTTPS.
- Set endpoint protocol Params:
-
#to_s ⇒ Object
Override the to_s method to return an endpoint fragment.
Constructor Details
#initialize(initial_path) ⇒ Endpoint
Creates the Endpoint object with default values for internal variables Params:
initial_path
-
Starting point of the URL this class will build
10 11 12 13 14 |
# File 'lib/client/helper/endpoint.rb', line 10 def initialize(initial_path) @path = { default: initial_path } @server = nil @protocol = "http://" end |
Instance Attribute Details
#server=(value) ⇒ Object (writeonly)
Set the @server variable externally
5 6 7 |
# File 'lib/client/helper/endpoint.rb', line 5 def server=(value) @server = value end |
Instance Method Details
#add(key, value) ⇒ Object
Add a section to the path Params:
key
-
Symbol, the key to identify the section
value
-
Any value to store with the associated key
27 28 29 |
# File 'lib/client/helper/endpoint.rb', line 27 def add(key, value) @path[key.to_sym] = value end |
#delete(key) ⇒ Object
Deletes a value from the internal hash based on a key Params:
key
-
Symbol, the key to identify the section
41 42 43 |
# File 'lib/client/helper/endpoint.rb', line 41 def delete(key) @path.delete(key) end |
#exists?(key) ⇒ Boolean
Checks whether a key exists Params:
key
-
Symbol, the key to identify the section
48 49 50 |
# File 'lib/client/helper/endpoint.rb', line 48 def exists?(key) @path.key? key end |
#get(key) ⇒ Object
Return a value based on the provided key Params:
key
-
Symbol, the key to identify the section
34 35 36 |
# File 'lib/client/helper/endpoint.rb', line 34 def get(key) @path[key.to_sym] end |
#protocol=(use_https) ⇒ Object
Set endpoint protocol Params:
use_https
-
Boolean value for whether to use HTTPS
19 20 21 |
# File 'lib/client/helper/endpoint.rb', line 19 def protocol=(use_https) @protocol = 'https://' if use_https end |
#to_s ⇒ Object
Override the to_s method to return an endpoint fragment
53 54 55 56 57 58 59 |
# File 'lib/client/helper/endpoint.rb', line 53 def to_s output = @protocol + @server @path.each_pair do |_k, value| output += value end output end |