Module: MKIt::Utils

Defined in:
lib/mkit/utils.rb

Constant Summary collapse

MKIT_CRT =
'mkit.crt'
MKIT_KEY =
'mkit.key'
MKIT_PEM =
'mkit.pem'

Class Method Summary collapse

Class Method Details

.config_dirObject



27
28
29
# File 'lib/mkit/utils.rb', line 27

def config_dir
  @config_dir.nil? ? "#{self.root}/config" : @config_dir
end

.db_config_to_uri(env = MKIt::Config.mkit.database.env) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mkit/utils.rb', line 40

def db_config_to_uri(env = MKIt::Config.mkit.database.env)
  config = self.load_db_config[env]

  if config["username"] || config["password"]
     = [ config["username"], config["password"] ].join(":")
  else
     = nil
  end
  URI::Generic.new(config["adapter"],,
                   config["hostname"] || "localhost",
                   config["port"],
                   nil,
                   "/#{config["database"]}",
                   nil,
                   nil,
                   nil).to_s
end

.load_db_config(db_config_dir = self.config_dir) ⇒ Object



35
36
37
38
# File 'lib/mkit/utils.rb', line 35

def load_db_config(db_config_dir = self.config_dir)
  self.log.info "loading database configurations from '#{config_dir}'..."
  YAML::load(ERB.new(IO.read("#{db_config_dir}/database.yml")).result)
end

.logObject



15
16
17
# File 'lib/mkit/utils.rb', line 15

def log
  Console.logger
end

.meObject



11
12
13
# File 'lib/mkit/utils.rb', line 11

def me
  'mkit'
end

.proxy_certObject



31
32
33
# File 'lib/mkit/utils.rb', line 31

def proxy_cert
  "#{config_dir}/#{MKIT_PEM}"
end

.rootObject



19
20
21
# File 'lib/mkit/utils.rb', line 19

def root
  File.expand_path("../../..", __FILE__)
end

.set_config_dir(config_dir) ⇒ Object



23
24
25
# File 'lib/mkit/utils.rb', line 23

def set_config_dir(config_dir)
  @config_dir = config_dir
end