Class: Vendorificator::Vendor::Download

Inherits:
Vendorificator::Vendor show all
Defined in:
lib/vendorificator/vendor/download.rb

Instance Attribute Summary collapse

Attributes inherited from Vendorificator::Vendor

#args, #block, #environment, #name

Instance Method Summary collapse

Methods inherited from Vendorificator::Vendor

#===, [], arg_reader, #branch_name, #category, #compute_dependencies!, compute_dependencies!, each, #head, #in_branch, #inspect, install!, instances, #merged, #merged_tag, #merged_version, #needed?, #run!, #shell, #status, #tag_message, #tag_name, #tag_name_base, #tagged_sha1, #to_s, #updatable?, #version, #work_dir, #work_subdir

Constructor Details

#initialize(environment, name, args = {}, &block) ⇒ Download

Returns a new instance of Download.



12
13
14
15
16
17
18
19
# File 'lib/vendorificator/vendor/download.rb', line 12

def initialize(environment, name, args={}, &block)
  no_url_given = !args[:url]

  args[:url] ||= name
  name = URI::parse(args[:url]).path.split('/').last if no_url_given

  super(environment, name, args, &block)
end

Instance Attribute Details

#conjured_checksumObject (readonly)

Returns the value of attribute conjured_checksum.



10
11
12
# File 'lib/vendorificator/vendor/download.rb', line 10

def conjured_checksum
  @conjured_checksum
end

Instance Method Details

#conjure!Object



25
26
27
28
29
30
31
# File 'lib/vendorificator/vendor/download.rb', line 25

def conjure!
  shell.say_status :download, url
  File.open name, 'w' do |outf|
    outf.write( open(url).read )
  end
  @conjured_checksum = Digest::SHA256.file(name).hexdigest
end

#conjure_commit_messageObject



37
38
39
40
41
# File 'lib/vendorificator/vendor/download.rb', line 37

def conjure_commit_message
  rv = "Conjured #{name} from #{url}\nChecksum: #{conjured_checksum}"
  rv << "Version: #{args[:version]}" if args[:version]
  rv
end

#pathObject



21
22
23
# File 'lib/vendorificator/vendor/download.rb', line 21

def path
  args[:path] || category
end

#upstream_versionObject



33
34
35
# File 'lib/vendorificator/vendor/download.rb', line 33

def upstream_version
  conjured_checksum || Digest::SHA256.hexdigest( open(url).read )
end