Class: RoboPigeon::Dsl::Root
- Inherits:
-
Object
- Object
- RoboPigeon::Dsl::Root
show all
- Includes:
- InitialJobs
- Defined in:
- lib/robopigeon/dsl.rb,
lib/robopigeon/jira.rb,
lib/robopigeon/slack.rb,
lib/robopigeon/gitlab.rb,
lib/robopigeon/dsl/job.rb,
lib/robopigeon/jenkins.rb
Constant Summary
Constants included
from InitialJobs
InitialJobs::INITIAL_FILE, InitialJobs::INITIAL_TEST, InitialJobs::TARGET_TEST
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#base, #init_help, #init_job, #init_new
Constructor Details
#initialize(file = RoboPigeon::DEFAULT_FILE) ⇒ Root
Returns a new instance of Root.
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/robopigeon/dsl.rb', line 11
def initialize(file = RoboPigeon::DEFAULT_FILE)
self.file = file
self.jobs = {}
base
init_help
init_new
if File.exist?(file)
contents = File.read(file)
instance_eval(contents, file)
else
init_job
end
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
9
10
11
|
# File 'lib/robopigeon/dsl.rb', line 9
def file
@file
end
|
#jobs ⇒ Object
Returns the value of attribute jobs.
9
10
11
|
# File 'lib/robopigeon/dsl.rb', line 9
def jobs
@jobs
end
|
Class Method Details
.run(&block) ⇒ Object
25
26
27
28
|
# File 'lib/robopigeon/dsl/job.rb', line 25
def self.run(&block)
instance = new
instance.instance_eval(&block)
end
|
Instance Method Details
#jenkins(&block) ⇒ Object
#job(*args, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/robopigeon/dsl/job.rb', line 30
def job(*args, &block)
initial_name = args.shift
this_job = {
desc: args.pop,
action: proc do
job = RoboPigeon::Dsl::Job.new
job.instance_eval(&block)
end
}
jobs[initial_name] = this_job
args.each do |arg|
jobs[arg] = this_job.merge(hidden: true)
end
end
|
#job?(name) ⇒ Boolean
29
30
31
|
# File 'lib/robopigeon/dsl.rb', line 29
def job?(name)
!jobs[name].nil?
end
|
#run(name) ⇒ Object
25
26
27
|
# File 'lib/robopigeon/dsl.rb', line 25
def run(name)
jobs[name][:action].call
end
|
#usage ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/robopigeon/dsl.rb', line 33
def usage
max_size = jobs.keys.reject(&:nil?).max_by(&:length).size
jobs_strings = jobs.keys.reject do |key|
key.nil? || jobs[key][:hidden]
end.map do |name|
padding = ' ' * (max_size - name.length)
" '#{name}' #{padding}- #{jobs[name][:desc]}"
end.join("\n")
puts "Usage: robopigeon 'job name'"
puts "Jobs are configured in #{file}"
puts 'See https://gitlab.com/pigeons/robopigeon for configuration'
puts "Configured Jobs:\n#{jobs_strings}"
end
|