Class: JenkinsPipelineBuilder::JobCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins_pipeline_builder/job_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJobCollection

Returns a new instance of JobCollection.



7
8
9
10
11
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 7

def initialize
  @collection = {}
  @remote_dependencies = RemoteDependencies.new self
  @loaded = false
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



3
4
5
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 3

def collection
  @collection
end

#loadedObject (readonly) Also known as: loaded?

Returns the value of attribute loaded.



4
5
6
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 4

def loaded
  @loaded
end

#remote_dependenciesObject

Returns the value of attribute remote_dependencies.



3
4
5
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 3

def remote_dependencies
  @remote_dependencies
end

Instance Method Details

#clear_remote_dependenciesObject



13
14
15
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 13

def clear_remote_dependencies
  @remote_dependencies = RemoteDependencies.new self
end

#defaultsObject



33
34
35
36
37
38
39
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 33

def defaults
  collection.each_value do |item|
    return item if item[:type] == 'defaults' || item[:type] == :defaults
  end
  # This is here for historical purposes
  get_item('global')
end

#get_item(name) ⇒ Object



41
42
43
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 41

def get_item(name)
  collection[name.to_s]
end

#jobsObject



29
30
31
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 29

def jobs
  collect_type :job
end

#load_from_path(path, remote = false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 45

def load_from_path(path, remote = false)
  load_extensions(path)
  path = File.expand_path(path, Dir.getwd)
  if File.directory?(path)
    logger.info "Generating from folder #{path}"
    Dir[File.join(path, '/*.{yaml,yml}')].each do |file|
      load_file(file, remote)
    end
    Dir[File.join(path, '/*.json')].each do |file|
      load_file(file, remote)
    end
  else
    load_file(path, remote)
  end
  @loaded = true
end

#loggerObject



17
18
19
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 17

def logger
  JenkinsPipelineBuilder.logger
end

#projectsObject



25
26
27
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 25

def projects
  collect_type :project
end

#standalone_jobsObject



21
22
23
# File 'lib/jenkins_pipeline_builder/job_collection.rb', line 21

def standalone_jobs
  jobs.map { |job| { result: job } }
end