Class: Cyclid::Client::Config
- Inherits:
-
Object
- Object
- Cyclid::Client::Config
- Includes:
- AuthMethods
- Defined in:
- lib/cyclid/config.rb
Overview
Cyclid client per-organization configuration
Constant Summary
Constants included from AuthMethods
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cyclid/config.rb', line 54 def initialize( = {}) # Load the config if a path was provided @path = [:path] || nil @config = @path.nil? ? nil : YAML.load_file(@path) # Select the authentication type & associated authentication data. @auth = [:auth] || AUTH_HMAC case @auth when AUTH_NONE # Nothing when AUTH_HMAC @secret = [:secret] || @config['secret'] when AUTH_BASIC @password = [:password] || @config['password'] when AUTH_TOKEN @token = [:token] || @config['token'] end # Set defaults from the options @server = [:server] || nil @port = [:port] || nil @organization = [:organization] || nil @username = [:username] || nil # Get anything provided in the config file if @config @server ||= @config['server'] @port ||= @config['port'] || 8361 @organization ||= @config['organization'] @username ||= @config['username'] end # Server & Username *must* be set raise 'server address must be provided' if @server.nil? raise 'username must be provided' if @username.nil? and @auth != AUTH_NONE end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def auth @auth end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def organization @organization end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def port @port end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def secret @secret end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def server @server end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def token @token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
22 23 24 |
# File 'lib/cyclid/config.rb', line 22 def username @username end |