Class: Traquitana::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
# File 'lib/config.rb', line 8

def initialize
  @configs  = {}
  @filename = 'config/traq.yml'
  @target   = nil
  load
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object



25
26
27
# File 'lib/config.rb', line 25

def method_missing(meth)
  @configs[meth.to_s] || ''
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#defaultObject



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

def default
  "#{File.dirname(File.expand_path(__FILE__))}/../config/default.yml"
end

#load(file = nil) ⇒ Object



19
20
21
22
23
# File 'lib/config.rb', line 19

def load(file = nil)
  check_configs(file)
  check_target
  check_default_target
end

#setupObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/config.rb', line 29

def setup
  STDOUT.puts 'Running setup'

  if File.exist?(self.filename)
    STDERR.puts "The configuration file #{self.filename} already exists."
    return false
  end

  dir = File.dirname(filename)
  Dir.mkdir(dir) if !File.exist?(dir)

  STDOUT.puts "Writing #{filename}"
  File.open(filename, "w") do |file|
    file << File.read(self.default)
  end

  STDOUT.puts "Setup completed!"
  STDOUT.puts "You MUST check the configurations on #{self.filename} before deploying!"
  true
end