Class: Imperium::Configuration
- Inherits:
-
Object
- Object
- Imperium::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/imperium/configuration.rb
Overview
The Configuration class represents the values necessary for making contact with a Consul agent.
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Integer
to open before failing, default: 5.
-
#receive_timeout ⇒ Integer
to open before failing, default: 60.
-
#send_timeout ⇒ Integer
finish uploading to Consul to open before failing, default: 15.
-
#token ⇒ String
APIs.
-
#url ⇒ Addressable::URI
the Consul agent.
Instance Method Summary collapse
-
#initialize(url: 'http://localhost:8500', token: nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#ssl=(value) ⇒ Object
Configure the clients to use SSL/TLS (or not).
-
#ssl? ⇒ Boolean
Check if the specified URL is using SSL/TLS.
-
#token? ⇒ Boolean
Check for the presence of a token.
Constructor Details
#initialize(url: 'http://localhost:8500', token: nil) ⇒ Configuration
Returns a new instance of Configuration.
30 31 32 33 34 35 36 |
# File 'lib/imperium/configuration.rb', line 30 def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end |
Instance Attribute Details
#connect_timeout ⇒ Integer
to open before failing, default: 5
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imperium/configuration.rb', line 24 class Configuration extend Forwardable attr_reader :url attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end def_delegators :@url, :host, :host=, :port, :port= # Check if the specified URL is using SSL/TLS # @return [Boolean] def ssl? @url.scheme == 'https' end # Configure the clients to use SSL/TLS (or not). # # @param value [Boolean] # @raise [NoMethodError] When the URL has previously been set to nil. def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end # Check for the presence of a token # @return [Boolean] def token? @token && !@token.empty? end # Set the URL # # This method will append a trailing slash to the supplied URL if not # included. We're doing this because merging a path onto a URL missing the # trailing slash will remove any extant path components. # # @param value [String, Addressable::URI, URI::GenericURI] The new value to use. def url=(value) if value.nil? @url = nil else @url = Addressable::URI.parse(value) @url.path << '/' unless @url.path.end_with?('/') end end end |
#receive_timeout ⇒ Integer
to open before failing, default: 60. This default is quite high in order to support long polling.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imperium/configuration.rb', line 24 class Configuration extend Forwardable attr_reader :url attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end def_delegators :@url, :host, :host=, :port, :port= # Check if the specified URL is using SSL/TLS # @return [Boolean] def ssl? @url.scheme == 'https' end # Configure the clients to use SSL/TLS (or not). # # @param value [Boolean] # @raise [NoMethodError] When the URL has previously been set to nil. def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end # Check for the presence of a token # @return [Boolean] def token? @token && !@token.empty? end # Set the URL # # This method will append a trailing slash to the supplied URL if not # included. We're doing this because merging a path onto a URL missing the # trailing slash will remove any extant path components. # # @param value [String, Addressable::URI, URI::GenericURI] The new value to use. def url=(value) if value.nil? @url = nil else @url = Addressable::URI.parse(value) @url.path << '/' unless @url.path.end_with?('/') end end end |
#send_timeout ⇒ Integer
finish uploading to Consul to open before failing, default: 15.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imperium/configuration.rb', line 24 class Configuration extend Forwardable attr_reader :url attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end def_delegators :@url, :host, :host=, :port, :port= # Check if the specified URL is using SSL/TLS # @return [Boolean] def ssl? @url.scheme == 'https' end # Configure the clients to use SSL/TLS (or not). # # @param value [Boolean] # @raise [NoMethodError] When the URL has previously been set to nil. def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end # Check for the presence of a token # @return [Boolean] def token? @token && !@token.empty? end # Set the URL # # This method will append a trailing slash to the supplied URL if not # included. We're doing this because merging a path onto a URL missing the # trailing slash will remove any extant path components. # # @param value [String, Addressable::URI, URI::GenericURI] The new value to use. def url=(value) if value.nil? @url = nil else @url = Addressable::URI.parse(value) @url.path << '/' unless @url.path.end_with?('/') end end end |
#token ⇒ String
APIs. Defaults to ‘nil`
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imperium/configuration.rb', line 24 class Configuration extend Forwardable attr_reader :url attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end def_delegators :@url, :host, :host=, :port, :port= # Check if the specified URL is using SSL/TLS # @return [Boolean] def ssl? @url.scheme == 'https' end # Configure the clients to use SSL/TLS (or not). # # @param value [Boolean] # @raise [NoMethodError] When the URL has previously been set to nil. def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end # Check for the presence of a token # @return [Boolean] def token? @token && !@token.empty? end # Set the URL # # This method will append a trailing slash to the supplied URL if not # included. We're doing this because merging a path onto a URL missing the # trailing slash will remove any extant path components. # # @param value [String, Addressable::URI, URI::GenericURI] The new value to use. def url=(value) if value.nil? @url = nil else @url = Addressable::URI.parse(value) @url.path << '/' unless @url.path.end_with?('/') end end end |
#url ⇒ Addressable::URI
the Consul agent. Defaults to ‘localhost:8500`
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imperium/configuration.rb', line 24 class Configuration extend Forwardable attr_reader :url attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token def initialize(url: 'http://localhost:8500', token: nil) @url = Addressable::URI.parse(url) @connect_timeout = 5 @send_timeout = 15 @receive_timeout = 60 @token = token end def_delegators :@url, :host, :host=, :port, :port= # Check if the specified URL is using SSL/TLS # @return [Boolean] def ssl? @url.scheme == 'https' end # Configure the clients to use SSL/TLS (or not). # # @param value [Boolean] # @raise [NoMethodError] When the URL has previously been set to nil. def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end # Check for the presence of a token # @return [Boolean] def token? @token && !@token.empty? end # Set the URL # # This method will append a trailing slash to the supplied URL if not # included. We're doing this because merging a path onto a URL missing the # trailing slash will remove any extant path components. # # @param value [String, Addressable::URI, URI::GenericURI] The new value to use. def url=(value) if value.nil? @url = nil else @url = Addressable::URI.parse(value) @url.path << '/' unless @url.path.end_with?('/') end end end |
Instance Method Details
#ssl=(value) ⇒ Object
Configure the clients to use SSL/TLS (or not).
50 51 52 |
# File 'lib/imperium/configuration.rb', line 50 def ssl=(value) @url.scheme = (!!value ? 'https' : 'http') end |
#ssl? ⇒ Boolean
Check if the specified URL is using SSL/TLS
42 43 44 |
# File 'lib/imperium/configuration.rb', line 42 def ssl? @url.scheme == 'https' end |
#token? ⇒ Boolean
Check for the presence of a token
56 57 58 |
# File 'lib/imperium/configuration.rb', line 56 def token? @token && !@token.empty? end |