Class: Vam::Vam

Inherits:
Object
  • Object
show all
Defined in:
lib/vam/vam.rb

Constant Summary collapse

SNAPSHOT =
'SNAPSHOT'

Instance Method Summary collapse

Constructor Details

#initialize(name, dsl, options) ⇒ Vam

Returns a new instance of Vam.



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

def initialize(name, dsl, options)
  @name = name
  @dsl = dsl

  @urls = []

  if options.include?(:version)
    @version = options[:version]
  else
    @version = @dsl.repo.latest_version @name
  end

  @files = @dsl.repo.files @name, @version

  tmproot = "#{VAMROOT}/#{@name}"
  @vroot = File.join tmproot, @version
  @vroot_tmp = File.join tmproot, ".tmp-#{@version}"

end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/vam/vam.rb', line 48

def cached?
  Dir.exist? @vroot
end

#copy(dest) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/vam/vam.rb', line 71

def copy(dest)
  if Dir.exist? dest
    FileUtils.rm_r dest
  end

  FileUtils.mkdir_p dest

  FileUtils.cp_r "#{@vroot}/.", dest
end

#downloadObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vam/vam.rb', line 53

def download
  FileUtils.mkdir_p @vroot_tmp

  @files.each do |file|
    dir = File.join @vroot_tmp, file[:dir]
    FileUtils.mkdir_p dir unless Dir.exist? dir
    df = File.join dir, file[:filename]

    open File.join(df), 'wb' do |s|
      puts "Download #{file[:url]}"
      s << open(file[:url]).read
    end
  end

  FileUtils.move @vroot_tmp, @vroot
end

#install(dest) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/vam/vam.rb', line 36

def install(dest)
  puts "===Install #{@name}===".colorize(:blue)
  if cached?
    puts 'Using cache...'
  else
    download
  end
  copy File.join(dest, @name)

end