Class: Cap::Vivo::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



13
14
15
16
17
18
# File 'lib/cap/vivo/configuration.rb', line 13

def initialize
  self.debug = env_boolean('DEBUG')
  logger_init
  @cap_repo = Cap.configuration.cap_repo
  @rdf_repo = Cap.configuration.rdf_repo
end

Instance Attribute Details

#cap_repoObject (readonly)

Returns the value of attribute cap_repo.



10
11
12
# File 'lib/cap/vivo/configuration.rb', line 10

def cap_repo
  @cap_repo
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



8
9
10
# File 'lib/cap/vivo/configuration.rb', line 8

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#rdf_repoObject (readonly)

Returns the value of attribute rdf_repo.



11
12
13
# File 'lib/cap/vivo/configuration.rb', line 11

def rdf_repo
  @rdf_repo
end

Instance Method Details

#env_boolean(var) ⇒ Object



20
21
22
23
# File 'lib/cap/vivo/configuration.rb', line 20

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cap/vivo/configuration.rb', line 35

def logger_init
  require 'logger'
  begin
    log_file = ENV['CAP_VIVO_LOG_FILE'] || 'log/cap_vivo_mapper.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