Class: LeeroyJenkins::JobRestorer
- Inherits:
-
Object
- Object
- LeeroyJenkins::JobRestorer
- Defined in:
- lib/leeroy_jenkins/job_restorer.rb
Instance Attribute Summary collapse
-
#backup_dir ⇒ Object
readonly
Returns the value of attribute backup_dir.
-
#jenkins_client ⇒ Object
readonly
Returns the value of attribute jenkins_client.
-
#job_names ⇒ Object
readonly
Returns the value of attribute job_names.
-
#job_regex ⇒ Object
readonly
Returns the value of attribute job_regex.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #dry_run ⇒ Object
-
#initialize(jenkins_client, backup_dir, threads, job_names, job_regex) ⇒ JobRestorer
constructor
A new instance of JobRestorer.
- #restore! ⇒ Object
Constructor Details
#initialize(jenkins_client, backup_dir, threads, job_names, job_regex) ⇒ JobRestorer
Returns a new instance of JobRestorer.
5 6 7 8 9 10 11 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 5 def initialize(jenkins_client, backup_dir, threads, job_names, job_regex) @jenkins_client = jenkins_client @backup_dir = backup_dir @threads = threads @job_names = job_names @job_regex = Regexp.new(job_regex) end |
Instance Attribute Details
#backup_dir ⇒ Object (readonly)
Returns the value of attribute backup_dir.
3 4 5 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3 def backup_dir @backup_dir end |
#jenkins_client ⇒ Object (readonly)
Returns the value of attribute jenkins_client.
3 4 5 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3 def jenkins_client @jenkins_client end |
#job_names ⇒ Object (readonly)
Returns the value of attribute job_names.
3 4 5 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3 def job_names @job_names end |
#job_regex ⇒ Object (readonly)
Returns the value of attribute job_regex.
3 4 5 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3 def job_regex @job_regex end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
3 4 5 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3 def threads @threads end |
Instance Method Details
#dry_run ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 13 def dry_run pairs = Parallel.map(config_xml_file_paths, in_threads: threads) do |xml_path| job_name = File.basename(xml_path, '.*') [job_name, File.read(xml_path)] end Result.new(Hash[pairs]) end |
#restore! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/leeroy_jenkins/job_restorer.rb', line 22 def restore! pairs = Parallel.map(config_xml_file_paths, in_threads: threads) do |xml_path| job_name = File.basename(xml_path, '.*') http_status_code = jenkins_client.job.create_or_update( job_name, File.read(xml_path) ) [job_name, http_status_code] end Result.new(Hash[pairs]) end |