class Traquitana::Config
Attributes
filename[RW]
target[RW]
Public Class Methods
new()
click to toggle source
# File lib/config.rb, line 8 def initialize @configs = {} @filename = 'config/traq.yml' @target = nil load end
Public Instance Methods
default()
click to toggle source
# File lib/config.rb, line 15 def default "#{File.dirname(File.expand_path(__FILE__))}/../config/default.yml" end
load(file = nil)
click to toggle source
# File lib/config.rb, line 19 def load(file = nil) check_configs(file) check_target check_default_target end
method_missing(meth)
click to toggle source
# File lib/config.rb, line 25 def method_missing(meth) @configs[meth.to_s] || '' end
setup()
click to toggle source
# File lib/config.rb, line 29 def setup STDOUT.puts 'Running setup' if File.exists?(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
Private Instance Methods
check_configs(file)
click to toggle source
# File lib/config.rb, line 52 def check_configs(file) @configs = YAML.load(File.read(file || self.filename)) rescue nil STDERR.puts "Configs not found (tried '#{file}' and '#{self.filename}')" if !@configs @configs end
check_default_target()
click to toggle source
# File lib/config.rb, line 70 def check_default_target if !@target && @configs && @configs["default"] STDOUT.puts "Loading default target ..." @configs = @configs["default"] end end
check_target()
click to toggle source
# File lib/config.rb, line 58 def check_target return if !@target || !@configs if !@configs[@target] STDERR.puts "Target #{@target} not found." exit(1) end @configs = @configs[@target] STDOUT.puts "Loaded #{@target} target." end