Class: Dply::AppConfig
- Inherits:
-
Object
show all
- Includes:
- Logger
- Defined in:
- lib/dply/app_config.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
#debug?, #logger, stderr, #stderr
Constructor Details
Returns a new instance of AppConfig.
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/dply/app_config.rb', line 14
def initialize
@tasks = {}
@config_map = {}
@namespace = nil
@inside_namespace = false
@config_read = false
@dsl_methods = self.class.instance_methods(false) + self.class.private_instance_methods(false)
def self.singleton_method_added(name)
raise Error, "overriding dsl method: :#{name} not allowed" if @dsl_methods.include? name
end
end
|
Class Method Details
.singleton_method_added(name) ⇒ Object
21
22
23
|
# File 'lib/dply/app_config.rb', line 21
def self.singleton_method_added(name)
raise Error, "overriding dsl method: :#{name} not allowed" if @dsl_methods.include? name
end
|
Instance Method Details
#load_config ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/dply/app_config.rb', line 59
def load_config
return if @config_read
bundler_setup
check_config_exists
read_config "drakefile.rb", optional: true
Dir["dply/*.rb"].each do |i|
read_config i
end
@config_read = true
end
|
#render_config ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/dply/app_config.rb', line 40
def render_config
load_config
require 'json'
config_data = load_yml "meta.yml", optional: true
tmp_file = "tmp/config_render.tmp"
config = lambda do |key|
value = config_data.dig(*key.split('.'))
raise "key #{key} not defined" if value.nil?
JSON.dump(value)
end
@config_map.each do |dest, src|
raise Error, %(error dest "#{dest}" is a directory) if File.directory? dest
template = File.read "dply/config/#{src}"
contents = ERB.new(template).result(binding)
File.write tmp_file, contents
FileUtils.mv tmp_file, dest
end
end
|
#run_task(name, optional: false) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/dply/app_config.rb', line 26
def run_task(name, optional: false)
load_config
name = name.to_s
task_proc = @tasks[name]
if task_proc
task_dsl = TaskDsl.new(self)
task_dsl.instance_eval &task_proc
elsif optional
logger.warn "task #{name} not found: skipping"
else
raise Error, "task '#{name}' not defined"
end
end
|