Class: Jenkins::JobDSL
- Inherits:
-
Object
- Object
- Jenkins::JobDSL
- Defined in:
- lib/dynport_tools/job_dsl.rb
Constant Summary collapse
- MULTIPLE =
[:notify, :cron_patterns, :locks, :commands]
Class Attribute Summary collapse
-
.jobs ⇒ Object
Returns the value of attribute jobs.
Instance Attribute Summary collapse
-
#current_prefix ⇒ Object
Returns the value of attribute current_prefix.
-
#current_scope ⇒ Object
Returns the value of attribute current_scope.
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #command_with_env(cmd, env = {}) ⇒ Object
- #disabled!(&block) ⇒ Object
-
#initialize(options = {}) ⇒ JobDSL
constructor
A new instance of JobDSL.
- #job(name, &block) ⇒ Object
- #rails_command(cmd, options = {}) ⇒ Object
- #rails_command_or_script(cmd_or_script, options = {}) ⇒ Object
- #rails_script(*args) ⇒ Object
- #rake_task(task, options = {}) ⇒ Object
- #runner_command(env = nil) ⇒ Object
- #setter_or_getter(key, *values, &block) ⇒ Object
- #use_bundle_exec! ⇒ Object
- #use_rails3! ⇒ Object
- #with(options, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JobDSL
Returns a new instance of JobDSL.
18 19 20 21 22 23 24 |
# File 'lib/dynport_tools/job_dsl.rb', line 18 def initialize( = {}) .each do |key, value| self.send(:"#{key}=", value) if self.respond_to?(:"#{key}=") end self.jobs = [] self.current_scope = {} end |
Class Attribute Details
.jobs ⇒ Object
Returns the value of attribute jobs.
4 5 6 |
# File 'lib/dynport_tools/job_dsl.rb', line 4 def jobs @jobs end |
Instance Attribute Details
#current_prefix ⇒ Object
Returns the value of attribute current_prefix.
16 17 18 |
# File 'lib/dynport_tools/job_dsl.rb', line 16 def current_prefix @current_prefix end |
#current_scope ⇒ Object
Returns the value of attribute current_scope.
16 17 18 |
# File 'lib/dynport_tools/job_dsl.rb', line 16 def current_scope @current_scope end |
#jobs ⇒ Object
Returns the value of attribute jobs.
16 17 18 |
# File 'lib/dynport_tools/job_dsl.rb', line 16 def jobs @jobs end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/dynport_tools/job_dsl.rb', line 16 def name @name end |
Class Method Details
.setup(namespace = :default, &block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/dynport_tools/job_dsl.rb', line 6 def setup(namespace = :default, &block) dsl = self.new dsl.instance_eval(&block) if block_given? self.jobs ||= {} self.jobs[namespace] ||= Array.new self.jobs[namespace] += dsl.jobs self.jobs[namespace] end |
Instance Method Details
#command_with_env(cmd, env = {}) ⇒ Object
79 80 81 |
# File 'lib/dynport_tools/job_dsl.rb', line 79 def command_with_env(cmd, env = {}) ((env || {}).sort.map { |key, value| "#{key}=#{value}" } + [@bundle_exec ? "bundle exec" : nil, cmd].compact).join(" ") end |
#disabled!(&block) ⇒ Object
44 45 46 |
# File 'lib/dynport_tools/job_dsl.rb', line 44 def disabled!(&block) disabled(true, &block) end |
#job(name, &block) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/dynport_tools/job_dsl.rb', line 104 def job(name, &block) if current_prefix @prefix_indexes ||= Hash.new(0) name = "#{current_prefix}%03d %s" % [@prefix_indexes[current_prefix] += 1, name] end job = JobDSL.new(self.current_scope.merge(:name => name)) job.instance_eval(&block) if block_given? self.jobs << job end |
#rails_command(cmd, options = {}) ⇒ Object
56 57 58 |
# File 'lib/dynport_tools/job_dsl.rb', line 56 def rails_command(cmd, = {}) rails_command_or_script(%("#{cmd.gsub('"', '\\"')}"), ) end |
#rails_command_or_script(cmd_or_script, options = {}) ⇒ Object
69 70 71 72 |
# File 'lib/dynport_tools/job_dsl.rb', line 69 def rails_command_or_script(cmd_or_script, = {}) raise "rails_root must be set" if rails_root.nil? command %(cd #{rails_root} && #{command_with_env(runner_command([:rails_env]), [:env])} #{cmd_or_script}) end |
#rails_script(*args) ⇒ Object
60 61 62 |
# File 'lib/dynport_tools/job_dsl.rb', line 60 def rails_script(*args) rails_command_or_script(*args) end |
#rake_task(task, options = {}) ⇒ Object
64 65 66 67 |
# File 'lib/dynport_tools/job_dsl.rb', line 64 def rake_task(task, = {}) [:env] = ([:env] || {}).merge("RAILS_ENV" => [:rails_env]) if [:rails_env] command "cd #{rails_root} && " + command_with_env("rake #{task}", [:env]) end |
#runner_command(env = nil) ⇒ Object
74 75 76 77 |
# File 'lib/dynport_tools/job_dsl.rb', line 74 def runner_command(env = nil) env ||= rails_env [@rails3 ? "rails runner" : "./script/runner", env ? "-e #{env}" : nil].compact.join(" ") end |
#setter_or_getter(key, *values, &block) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/dynport_tools/job_dsl.rb', line 94 def setter_or_getter(key, *values, &block) value = MULTIPLE.include?(key) ? values : values.first if block_given? with(key => value, &block) elsif ![[], nil].include?(value) self.send(:"#{key}=", value) end self.instance_variable_get("@#{key}") end |
#use_bundle_exec! ⇒ Object
52 53 54 |
# File 'lib/dynport_tools/job_dsl.rb', line 52 def use_bundle_exec! @bundle_exec = true end |
#use_rails3! ⇒ Object
48 49 50 |
# File 'lib/dynport_tools/job_dsl.rb', line 48 def use_rails3! @rails3 = true end |
#with(options, &block) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/dynport_tools/job_dsl.rb', line 83 def with(, &block) old_scope = self.current_scope self.current_scope = self.current_scope.merge() self.instance_eval(&block) self.current_scope = old_scope end |