Class: UploadRunner

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/bento/upload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#banner, #box_metadata, #build_list, #builds_yml, #duration, #info, #macos?, #metadata_files, #private_box?, #unix?, #vc_account, #warn, #windows?

Constructor Details

#initialize(opts) ⇒ UploadRunner

Returns a new instance of UploadRunner.



8
9
10
# File 'lib/bento/upload.rb', line 8

def initialize(opts)
  @md_json = opts.md_json
end

Instance Attribute Details

#md_jsonObject (readonly)

Returns the value of attribute md_json.



6
7
8
# File 'lib/bento/upload.rb', line 6

def md_json
  @md_json
end

Instance Method Details

#startObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/bento/upload.rb', line 12

def start
  banner("Starting uploads...")
  time = Benchmark.measure do
    files = md_json ? [md_json] : 
    files.each do |md_file|
      upload(md_file)
    end
  end
  banner("Uploads finished in #{duration(time.real)}.")
end

#upload(md_file) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bento/upload.rb', line 23

def upload(md_file)
  puts "Attempting to upload #{md_file}"
  md = (md_file)
  box_desc = "a bento box for #{md['name']}"
  box = .ensure_box(md["name"], {short_description: box_desc, is_private: private_box?(md["name"])})
  box_ver = box.ensure_version(md["version"], File.read(md_file))

  if builds_yml["slugs"].value?(box.name)
    slug_desc = "a bento box for #{builds_yml['slugs'].key(box.name)}"
    slug = .ensure_box(builds_yml["slugs"].key(box.name), {short_description: slug_desc, is_private: false})
    slug_ver = slug.ensure_version(md["version"], File.read(md_file))
  end

  md["providers"].each do |k, v|
    provider = box_ver.ensure_provider(k, nil)
    banner("Uploading #{box.name}/#{box_ver.version}/#{provider.name}...")
    provider.upload_file("builds/#{v['file']}")
    banner(provider.download_url.to_s)
    next unless builds_yml["slugs"].value?(box.name)

    slug_provider = slug_ver.ensure_provider(k, nil)
    banner("Uploading #{slug.name}/#{slug_ver.version}/#{slug_provider.name}...")
    slug_provider.upload_file("builds/#{v['file']}")
    banner(slug_provider.download_url.to_s)
  end
end