Class: Cap::Client::Configuration
- Inherits:
-
Object
- Object
- Cap::Client::Configuration
- Defined in:
- lib/cap/client/configuration.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#token_pass ⇒ Object
Returns the value of attribute token_pass.
-
#token_user ⇒ Object
Parameters for authentication.
Instance Method Summary collapse
- #env_boolean(var) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #logger_init ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 |
# File 'lib/cap/client/configuration.rb', line 14 def initialize self.debug = env_boolean('DEBUG') logger_init # Parameters for triannon client authentication @token_user = ENV['CAP_TOKEN_USER'] || '' @token_pass = ENV['CAP_TOKEN_PASS'] || '' end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
6 7 8 |
# File 'lib/cap/client/configuration.rb', line 6 def debug @debug end |
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
8 9 10 |
# File 'lib/cap/client/configuration.rb', line 8 def log_file @log_file end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/cap/client/configuration.rb', line 7 def logger @logger end |
#token_pass ⇒ Object
Returns the value of attribute token_pass.
12 13 14 |
# File 'lib/cap/client/configuration.rb', line 12 def token_pass @token_pass end |
#token_user ⇒ Object
Parameters for authentication
11 12 13 |
# File 'lib/cap/client/configuration.rb', line 11 def token_user @token_user end |
Instance Method Details
#env_boolean(var) ⇒ Object
22 23 24 25 |
# File 'lib/cap/client/configuration.rb', line 22 def env_boolean(var) # check if an ENV variable is true, use false as default ENV[var].to_s.upcase == 'TRUE' rescue false end |
#logger_init ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cap/client/configuration.rb', line 37 def logger_init require 'logger' begin log_file = ENV['CAP_CLIENT_LOG_FILE'] || 'log/cap_client.log' @log_file = File.absolute_path log_file FileUtils.mkdir_p File.dirname(@log_file) rescue nil log_dev = File.new(@log_file, 'w+') rescue log_dev = $stderr @log_file = 'STDERR' end log_dev.sync = true if @debug # skip IO buffering in debug mode @logger = Logger.new(log_dev, 'weekly') @logger.level = @debug ? Logger::DEBUG : Logger::INFO end |