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.

Parameters:

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:



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' ...>

Parameters:

  • name (String)

    the name of the build component

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:

  • (Resource::BuildComponent, nil)

    an instance of the build component that matches the given name, or nil if one does not exist



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>, ...]

Returns:



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

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (Boolean)

    true if the object was deleted successfully, false otherwise



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

Returns:

  • (Object)


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

attribute :last_started

#last_started=(value) ⇒ Object

Set this object’s last_started

Parameters:

  • value (Object)

    the value to set for last_started

  • default (Object)

    the default value for this attribute



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

Returns:

  • (Boolean)


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

attribute :last_started

#nameObject

Return this object’s name

Returns:

  • (Object)


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

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

#name=(value) ⇒ Object

Set this object’s name

Parameters:

  • value (Object)

    the value to set for name

  • default (Object)

    the default value for this attribute



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

Returns:

  • (Boolean)


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

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

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

Rename a build component.

Parameters:

  • new_name (String)

    new name for the component

Returns:

  • (Boolean)

    true if the object was renamed successfully, false otherwise



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

Returns:

  • (Object)


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

attribute :uri

#uri=(value) ⇒ Object

Set this object’s uri

Parameters:

  • value (Object)

    the value to set for uri

  • default (Object)

    the default value for this attribute



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

attribute :uri

#uri?Boolean

Determines if the uri value exists and is truthy

Returns:

  • (Boolean)


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

attribute :uri