Class: Ramekin::AMKSetup::Setup

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ramekin/amk_setup.rb

Direct Known Subclasses

NormalSetup, WindowsSetup

Constant Summary

Constants included from Util

Util::KNOWN_LENGTHS

Instance Method Summary collapse

Methods included from Util

#adsr_value, #extra_nice_length_amk, #nice_length_amk

Constructor Details

#initialize(force: false) ⇒ Setup



28
29
30
# File 'lib/ramekin/amk_setup.rb', line 28

def initialize(force: false)
  @force = force
end

Instance Method Details

#error!(msg) ⇒ Object



32
33
34
35
# File 'lib/ramekin/amk_setup.rb', line 32

def error!(msg)
  $stderr.puts(msg)
  exit 1
end

#latest_tag(repo, host = 'github.com') ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ramekin/amk_setup.rb', line 37

def latest_tag(repo, host='github.com')
  host = 'api.github.com' if host == 'github.com'
  host = 'codeberg.org/api/v1' if host == 'codeberg.org'

  tag_info = JSON.parse(URI.open("https://#{host}/repos/#{repo}/git/refs/tags").read)
  tag_info.last['ref']
end

#unpack_repo_source!(repo, dir, host: 'github.com') ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ramekin/amk_setup.rb', line 45

def unpack_repo_source!(repo, dir, host: 'github.com')
  clear_dir(dir, force: @force) or return false

  tag = latest_tag(repo, host)
  tag = File.basename(tag) if host == 'codeberg.org'

  source_url = "https://#{host}/#{repo}/archive/#{tag}.zip"

  Dir.chdir(dir) do
    zip = URI.open(source_url).read
    $stderr.puts "extracting #{repo} from #{source_url}"
    $stderr.puts "into #{dir}"
    unpack_zip_here(zip) do |name|
      $stderr.puts " -> #{name}"
    end
  end

  true
end