Class: NexusArtifact
- Inherits:
-
Object
- Object
- NexusArtifact
- Defined in:
- lib/nexus_artifact.rb,
lib/nexus_artifact/version.rb
Constant Summary collapse
- PATTERN_MAP =
{ '%v' => :ver, '%e' => :ext, }
- VERSION =
"2.0.1"
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#base_href ⇒ Object
readonly
Returns the value of attribute base_href.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
Instance Method Summary collapse
- #auth(user, pass) ⇒ Object
- #builds(base) ⇒ Object
- #get(file, data) ⇒ Object
-
#initialize(base_uri, base_path, pattern) ⇒ NexusArtifact
constructor
A new instance of NexusArtifact.
- #next_version(base) ⇒ Object
- #publish(file, data) ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(base_uri, base_path, pattern) ⇒ NexusArtifact
Returns a new instance of NexusArtifact.
27 28 29 30 31 32 |
# File 'lib/nexus_artifact.rb', line 27 def initialize(base_uri, base_path, pattern) @base_uri = base_uri @base_href = "#{base_uri}#{base_path}" @pattern = pattern @agent = Mechanize.new end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
25 26 27 |
# File 'lib/nexus_artifact.rb', line 25 def agent @agent end |
#base_href ⇒ Object (readonly)
Returns the value of attribute base_href.
25 26 27 |
# File 'lib/nexus_artifact.rb', line 25 def base_href @base_href end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
25 26 27 |
# File 'lib/nexus_artifact.rb', line 25 def base_uri @base_uri end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
25 26 27 |
# File 'lib/nexus_artifact.rb', line 25 def pattern @pattern end |
Class Method Details
.instance ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nexus_artifact.rb', line 14 def self.instance @instance ||= begin yml = YAML.load File.read('nexus.yml') obj = new yml[:uri], yml[:path], yml[:artifact] if yml[:user] && yml[:pass] obj.auth yml[:user], yml[:pass] end obj end end |
Instance Method Details
#auth(user, pass) ⇒ Object
34 35 36 37 |
# File 'lib/nexus_artifact.rb', line 34 def auth(user, pass) agent.add_auth(base_uri, user, pass) self end |
#builds(base) ⇒ Object
46 47 48 49 50 |
# File 'lib/nexus_artifact.rb', line 46 def builds(base) versions.map do |v| $1.to_i if v.start_with?(base) && v[base.size .. -1] =~ /\A\.(\d+)\Z/ end.compact.sort end |
#get(file, data) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/nexus_artifact.rb', line 57 def get(file, data) path = path(data) sha1_expected = call(:get_file, path + '.sha1').to_s.strip download(path, file) sha1_actual = Digest::SHA1.file(file).hexdigest if sha1_expected != sha1_actual raise "SHA1 mismatch for #{file}. Expected #{sha1_expected.inspect} but got #{sha1_actual.inspect}." end end |
#next_version(base) ⇒ Object
52 53 54 55 |
# File 'lib/nexus_artifact.rb', line 52 def next_version(base) max = builds(base).max || -1 "#{base}.#{max + 1}" end |
#publish(file, data) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nexus_artifact.rb', line 67 def publish(file, data) path = path(data) uploads = [ [path, File.read(file)], [path + '.sha1', Digest::SHA1.file(file).hexdigest], ([path + '.git', data[:git]] if data[:git]), ] uploads.each do |path, contents| raise "#{path} already exists" if call(:head, path) end uploads.each do |path, contents| call(:put, path, contents) end nil end |
#versions ⇒ Object
39 40 41 42 43 44 |
# File 'lib/nexus_artifact.rb', line 39 def versions pg = call(:get, '') or return [] pg.links.map do |link| link.text.gsub('/', '') if link.href.start_with? base_href end.compact end |