Class: Cap::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cap/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
19
# File 'lib/cap/configuration.rb', line 13

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

Instance Attribute Details

#cap_repoObject (readonly)

Returns the value of attribute cap_repo.



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

def cap_repo
  @cap_repo
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



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

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#rdf_replaceObject (readonly)

Returns the value of attribute rdf_replace.



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

def rdf_replace
  @rdf_replace
end

#rdf_repoObject (readonly)

Returns the value of attribute rdf_repo.



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

def rdf_repo
  @rdf_repo
end

Instance Method Details

#cap_repo_daybreakObject



69
70
71
72
73
74
75
76
# File 'lib/cap/configuration.rb', line 69

def cap_repo_daybreak
  @cap_repo_daybreak ||= begin
    dir = File.dirname(@log_file)
    db = Daybreak::DB.new File.join(dir,'cap_profiles.db')
    db.load if db.size > 0
    db
  end
end

#cap_repo_mongoObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cap/configuration.rb', line 78

def cap_repo_mongo
  @cap_repo_mongo ||= begin
    dir = File.dirname(@log_file)
    log_file = File.join(dir,'cap_repo_mongo.log')
    log_dev = File.new(log_file, 'w+')
    log_dev.sync = true if @debug # skip IO buffering in debug mode
    logger = Logger.new(log_dev, 'weekly')
    logger.level = @debug ? Logger::INFO : Logger::WARN
    Mongo::Logger.logger = logger
    repo = ENV['CAP_REPO_MONGO'].dup || 'mongodb://127.0.0.1:27017/cap'
    Mongo::Client.new(repo)
  end
end

#env_boolean(var) ⇒ Object



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

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



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

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