Class: Artifactory::Resource::BuildComponent

Inherits:
Base
  • Object
show all
Defined in:
lib/artifactory/resources/build_component.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attribute, attributes, #attributes, #client, #client=, #client?, #extract_client!, extract_client!, find_from_config, format_repos!, #format_repos!, from_url, has_attribute?, #initialize, #inspect, list_from_config, #set, #to_hash, #to_json, #to_matrix_properties, #to_query_string_parameters, #to_s, url_safe, #url_safe

Constructor Details

This class inherits a constructor from Artifactory::Resource::Base

Class Method Details

.all(options = {}) ⇒ Array<Resource::BuildComponent>

Search for all compoenents for which build data exists.

Options Hash (options):



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/artifactory/resources/build_component.rb', line 34

def all(options = {})
  client = extract_client!(options)
  client.get('/api/build')['builds'].map do |component|
    from_hash(component, client: client)
  end.compact.flatten
rescue Error::HTTPError => e
  # Artifactory returns a 404 instead of an empty list when there are no
  # builds. Whoever decided that was a good idea clearly doesn't
  # understand the point of REST interfaces...
  raise unless e.code == 404
  []
end

.find(name, options = {}) ⇒ Resource::BuildComponent?

Find (fetch) data for a particular build component

Examples:

Find a particular build component

BuildComponent.find('wicket') #=> #<BuildComponent name: 'wicket' ...>

Options Hash (options):



65
66
67
68
69
70
# File 'lib/artifactory/resources/build_component.rb', line 65

def find(name, options = {})
  client = extract_client!(options)
  all.find do |component|
    component.name == name
  end
end

.from_hash(hash, options = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/artifactory/resources/build_component.rb', line 75

def from_hash(hash, options = {})
  super.tap do |instance|
    # Remove the leading / from the `uri` value. Converts `/foo` to `foo`.
    instance.name = instance.uri.slice(1..-1)
    instance.last_started = Time.parse(instance.last_started) rescue nil
  end
end

Instance Method Details

#buildsCollection::Build

The list of build data for this component.

Examples:

Get the list of artifacts for a repository

component = BuildComponent.new(name: 'wicket')
component.builds #=> [#<Resource::Build>, ...]


98
99
100
101
102
# File 'lib/artifactory/resources/build_component.rb', line 98

def builds
  @builds ||= Collection::Build.new(self, name: name) do
    Resource::Build.all(name)
  end
end

#delete(options = {}) ⇒ Boolean

Remove this component’s build data stored in Artifactory

Options Hash (options):

  • :build_numbers (Array<String>) — default: default: nil

    an array of build numbers that should be deleted; if not given all builds (for this component) are deleted

  • :artifacts (Boolean) — default: default: +false+

    if true the component’s artifacts are also removed

  • :delete_all (Boolean) — default: default: +false+

    if true the entire component is removed



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/artifactory/resources/build_component.rb', line 118

def delete(options = {})
  params = {}.tap do |param|
    param[:buildNumbers] = options[:build_numbers].join(',') if options[:build_numbers]
    param[:artifacts]    = 1 if options[:artifacts]
    param[:deleteAll]    = 1 if options[:delete_all]
  end

  endpoint = api_path + "?#{to_query_string_parameters(params)}"
  client.delete(endpoint, {})
  true
rescue Error::HTTPError => e
  false
end

#last_startedObject

Return this object’s last_started



86
# File 'lib/artifactory/resources/build_component.rb', line 86

attribute :last_started

#last_started=(value) ⇒ Object

Set this object’s last_started



86
# File 'lib/artifactory/resources/build_component.rb', line 86

attribute :last_started

#last_started?Boolean

Determines if the last_started value exists and is truthy



86
# File 'lib/artifactory/resources/build_component.rb', line 86

attribute :last_started

#nameObject

Return this object’s name



85
# File 'lib/artifactory/resources/build_component.rb', line 85

attribute :name, ->{ raise 'Name missing!' }

#name=(value) ⇒ Object

Set this object’s name



85
# File 'lib/artifactory/resources/build_component.rb', line 85

attribute :name, ->{ raise 'Name missing!' }

#name?Boolean

Determines if the name value exists and is truthy



85
# File 'lib/artifactory/resources/build_component.rb', line 85

attribute :name, ->{ raise 'Name missing!' }

#rename(new_name, options = {}) ⇒ Boolean

Rename a build component.



141
142
143
144
145
146
147
# File 'lib/artifactory/resources/build_component.rb', line 141

def rename(new_name, options = {})
  endpoint = "/api/build/rename/#{url_safe(name)}" + "?to=#{new_name}"
  client.post(endpoint, {})
  true
rescue Error::HTTPError => e
  false
end

#uriObject

Return this object’s uri



84
# File 'lib/artifactory/resources/build_component.rb', line 84

attribute :uri

#uri=(value) ⇒ Object

Set this object’s uri



84
# File 'lib/artifactory/resources/build_component.rb', line 84

attribute :uri

#uri?Boolean

Determines if the uri value exists and is truthy



84
# File 'lib/artifactory/resources/build_component.rb', line 84

attribute :uri