Module: Buildr::ActsAsArtifact

Included in:
Artifact
Defined in:
lib/core/artifact.rb

Overview

This module gives you a way to access the individual properties of an artifact: id, group, type, classifier and version. It also provides other methods commonly used on an artifact, specifically #to_hash and #to_spec.

Constant Summary collapse

ARTIFACT_ATTRIBUTES =
[:group, :id, :type, :classifier, :version]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#classifierObject (readonly)

Optional artifact classifier.



25
26
27
# File 'lib/core/artifact.rb', line 25

def classifier
  @classifier
end

#groupObject (readonly)

The group identifier.



19
20
21
# File 'lib/core/artifact.rb', line 19

def group
  @group
end

#idObject (readonly)

The artifact identifier.



17
18
19
# File 'lib/core/artifact.rb', line 17

def id
  @id
end

#typeObject (readonly)

The file type.



21
22
23
# File 'lib/core/artifact.rb', line 21

def type
  @type
end

#versionObject (readonly)

The version number.



23
24
25
# File 'lib/core/artifact.rb', line 23

def version
  @version
end

Class Method Details

.included(mod) ⇒ Object



11
12
13
# File 'lib/core/artifact.rb', line 11

def included(mod)
  mod.extend self
end

Instance Method Details

#apply_spec(spec) ⇒ Object

Apply specification to this artifact.



43
44
45
46
47
# File 'lib/core/artifact.rb', line 43

def apply_spec(spec)
  spec = Artifact.to_hash(spec)
  ARTIFACT_ATTRIBUTES.each { |key| instance_variable_set("@#{key}", spec[key]) }
  self
end

#pomObject

Convenience method that returns a POM artifact.



50
51
52
53
# File 'lib/core/artifact.rb', line 50

def pom()
  return self if type.to_s == "pom"
  artifact(:group=>group, :id=>id, :version=>version, :type=>"pom", :classifier=>classifier)
end

#to_specObject

Returns the artifact specification, in the structure:

<group>:<artifact>:<type>:<version>

or

<group>:<artifact>:<type>:<classifier><:<version>


38
39
40
# File 'lib/core/artifact.rb', line 38

def to_spec()
  classifier.blank? ? "#{group}:#{id}:#{type}:#{version}" : "#{group}:#{id}:#{type}:#{classifier}:#{version}"
end

#to_spec_hashObject Also known as: to_hash

Returns the artifact specification as a hash.



28
29
30
31
# File 'lib/core/artifact.rb', line 28

def to_spec_hash()
  base = { :group=>group, :id=>id, :type=>type, :version=>version }
  classifier.blank? ? base : base.merge(:classifier=>classifier)
end