Class: Warbler::WebServer::Artifact

Inherits:
Struct
  • Object
show all
Defined in:
lib/warbler/web_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#artifact_idObject

Returns the value of attribute artifact_id

Returns:

  • (Object)

    the current value of artifact_id


3
4
5
# File 'lib/warbler/web_server.rb', line 3

def artifact_id
  @artifact_id
end

#group_idObject

Returns the value of attribute group_id

Returns:

  • (Object)

    the current value of group_id


3
4
5
# File 'lib/warbler/web_server.rb', line 3

def group_id
  @group_id
end

#repoObject

Returns the value of attribute repo

Returns:

  • (Object)

    the current value of repo


3
4
5
# File 'lib/warbler/web_server.rb', line 3

def repo
  @repo
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version


3
4
5
# File 'lib/warbler/web_server.rb', line 3

def version
  @version
end

Instance Method Details

#cached_pathObject


8
9
10
# File 'lib/warbler/web_server.rb', line 8

def cached_path
  @cached_path ||= File.expand_path("~/.m2/repository/#{path_fragment}")
end

#download_urlObject


12
13
14
# File 'lib/warbler/web_server.rb', line 12

def download_url
  @download_url ||= "#{repo}/#{path_fragment}" #:nocov:
end

#local_pathObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/warbler/web_server.rb', line 16

def local_path
  unless File.exist?(cached_path)
    puts "Downloading #{artifact_id}-#{version}.jar" #:nocov:
    FileUtils.mkdir_p File.dirname(cached_path) #:nocov:
    require 'open-uri'                    #:nocov:
    begin
      open(download_url) do |stream|        #:nocov:
        File.open(cached_path, "wb") do |f| #:nocov:
          while buf = stream.read(4096) #:nocov:
            f << buf                    #:nocov:
          end                           #:nocov:
        end                             #:nocov:
      end                               #:nocov:
    rescue => e
      e.message.concat " - #{download_url}"
      raise e
    end
  end
  cached_path
end

#path_fragmentObject


4
5
6
# File 'lib/warbler/web_server.rb', line 4

def path_fragment
  @path_fragment ||= "#{group_id.gsub('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.jar"
end