Module: Skiima::Config

Included in:
Skiima, Loader
Defined in:
lib/skiima/config.rb,
lib/skiima/config/struct.rb

Defined Under Namespace

Classes: Struct

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



56
57
58
# File 'lib/skiima/config.rb', line 56

def method_missing(method, *args, &block)
  config.respond_to?(method) ? config.send(method, *args) : super
end

Instance Method Details

#configObject



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

def config
  @config ||= (Skiima::Config::Struct.new(defaults.to_hash))
end

#config=(struct) ⇒ Object



9
10
11
# File 'lib/skiima/config.rb', line 9

def config=(struct)
  @config = struct
end

#full_database_path(root = self.root_path, config = self.config_path, db = self.database_yml) ⇒ Object



17
18
19
# File 'lib/skiima/config.rb', line 17

def full_database_path(root = self.root_path, config = self.config_path, db = self.database_yml)
  File.join(root, config, db)
end

#full_dependencies_path(root = self.root_path, config = self.scripts_path, dependencies = self.dependencies_yml) ⇒ Object



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

def full_dependencies_path(root = self.root_path, config = self.scripts_path, dependencies = self.dependencies_yml)
  File.join(root, config, dependencies)
end

#full_scripts_path(root = self.root_path, config = self.scripts_path) ⇒ Object



13
14
15
# File 'lib/skiima/config.rb', line 13

def full_scripts_path(root = self.root_path, config = self.scripts_path)
  File.join(root, config)
end

#interpolate_sql(char, sql, vars = {}) ⇒ Object



52
53
54
# File 'lib/skiima/config.rb', line 52

def interpolate_sql(char, sql, vars = {})
  vars.inject(sql) { |m,(k,v)| m.gsub("#{char}#{k.to_s}", v) }
end

#read_db_yml(file) ⇒ Object



29
30
31
# File 'lib/skiima/config.rb', line 29

def read_db_yml(file)
  symbolize_keys(read_yml_or_throw(file, MissingFileException, "#{Skiima.msg('errors.open_db_yml')} #{file}"))
end

#read_dependencies_yml(file) ⇒ Object



33
34
35
# File 'lib/skiima/config.rb', line 33

def read_dependencies_yml(file)
  symbolize_keys(read_yml_or_throw(file, MissingFileException, "#{Skiima.msg('errors.open_dependencies_yml')} #{file}"))
end

#read_sql_file(folder, file) ⇒ Object



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

def read_sql_file(folder, file)
  File.open(File.join(Skiima.full_scripts_path, folder, file)).read
end

#read_yml_or_throw(file, errclass, errmsg) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/skiima/config.rb', line 37

def read_yml_or_throw(file, errclass, errmsg)
  input = File.read(file)
  eruby = Erubis::Eruby.new(input)
  symbolize_keys(YAML::load(eruby.result(binding()))) || {}
rescue => ex
  raise errclass, errmsg
end

#symbolize_keys(hash) ⇒ Object



45
46
47
48
49
50
# File 'lib/skiima/config.rb', line 45

def symbolize_keys(hash)
  hash.inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end