Module: Grably::Core::TaskExtensions::Jobs
Overview
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/grably/core/task/jobs.rb', line 7
def method_missing(meth, *args, &block)
job_class = find_job_class(meth.to_s)
if job_class
execute_job_with_args(args, job_class, meth)
else
super
end
end
|
Instance Method Details
#execute_job_with_args(args, job_class, meth) ⇒ Object
16
17
18
19
20
|
# File 'lib/grably/core/task/jobs.rb', line 16
def execute_job_with_args(args, job_class, meth)
working_dir = job_dir(task_dir, meth.to_s)
FileUtils.mkdir_p(working_dir)
job_class.new.run(self, working_dir, *args)
end
|
#job_dir(base_dir, job_name) ⇒ String
Create working directory for instantiated job inside task directory
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/grably/core/task/jobs.rb', line 26
def job_dir(base_dir, job_name)
counter = (jobs[job_name] || -1) + 1
jobs[job_name] = counter
name = [job_name, counter.to_s.rjust(3, '0')].join('-')
File.join(base_dir, name)
end
|
#jobs ⇒ Object
37
38
39
|
# File 'lib/grably/core/task/jobs.rb', line 37
def jobs
@jobs ||= {}
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
41
42
43
|
# File 'lib/grably/core/task/jobs.rb', line 41
def respond_to_missing?(meth, include_private = false)
find_job_class(meth) || super
end
|