Class: Cap::Client::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cap/client/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#debugObject

Returns the value of attribute debug.



6
7
8
# File 'lib/cap/client/configuration.rb', line 6

def debug
  @debug
end

#log_fileObject (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

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/cap/client/configuration.rb', line 7

def logger
  @logger
end

#token_passObject

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_userObject

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_initObject



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