class Migrate::Conf
Attributes
root[R]
Public Class Methods
new(root, file)
click to toggle source
# File lib/migrate/conf.rb, line 7 def initialize(root, file) @root = root @file=file @file_path = "#{root}/#{file}" @loaded = false end
Public Instance Methods
delete()
click to toggle source
# File lib/migrate/conf.rb, line 54 def delete if File.exists? @file_path File.delete @file_path end rescue Exception => e Log.error("Error while removing configuration file.", e) exit end
exists?()
click to toggle source
# File lib/migrate/conf.rb, line 14 def exists? File.exist? @file_path end
get_db()
click to toggle source
# File lib/migrate/conf.rb, line 63 def get_db case @storage when "pg" if @pg == nil require_relative "./storage/postgres" @pg = Storage::Postgres.new(self) end @pg when "mysql" if @mysql == nil require_relative "./storage/mysql" @mysql = Storage::Mysql.new(self) end @mysql end end
get_lang()
click to toggle source
# File lib/migrate/conf.rb, line 82 def get_lang case @lang when "sql" if @sql == nil @sql = Lang::Sql.new(get_db) end @sql when "javascript" if @javascript == nil @javascript = Lang::Javascript.new end @javascript when "ruby" if @ruby == nil @ruby = Lang::Ruby.new end @ruby when "go" if @go == nil @go = Lang::Go.new end @go when "python" if @python == nil @python = Lang::Python.new end @python end end
init(config)
click to toggle source
# File lib/migrate/conf.rb, line 18 def init(config) if not Dir.exist? @root Dir.mkdir @root end File.open(@file_path, "w") do |f| config.map do |key, value| f.puts "#{key}=#{value}\n" end end Log.success("Configuration file created. Location: `#{@file_path}`") end
load!()
click to toggle source
# File lib/migrate/conf.rb, line 32 def load! Log.info("Loading configuration...") config = ParseConfig.new(@file_path) config.get_params.map do |param| value = nil env_var = config[param].match(/\$\{(.*)\}/) if env_var != nil value = ENV[env_var[1]] else value = config[param] end self.class.send(:attr_reader, param) instance_variable_set("@#{param}", value) end @loaded = true Log.success("Configuration loaded.") end