Class: Qas::Archive

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

Overview

Archive FLOSS Projects

Constant Summary collapse

ARCHIVED =

Folder to store compressed projects

Pathname.new(File.join(Dir.home, 'Downloads', 'archived'))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, names, fmt = 'tar') ⇒ Archive

Returns a new instance of Archive.



22
23
24
25
26
27
# File 'lib/qas/archive.rb', line 22

def initialize(project, names, fmt = 'tar')
  @project = project
  @names = names
  @format = fmt
  @fullpath = "#{ARCHIVED.join(project.name)}.#{@format}"
end

Instance Attribute Details

#formatObject (readonly)

Format to be compressed



11
12
13
# File 'lib/qas/archive.rb', line 11

def format
  @format
end

#namesObject (readonly)

FLOSS Projects elected to be archived



14
15
16
# File 'lib/qas/archive.rb', line 14

def names
  @names
end

#projectObject (readonly)

project



17
18
19
# File 'lib/qas/archive.rb', line 17

def project
  @project
end

Instance Method Details

#archiveObject

Archiving FLOSS project



30
31
32
33
34
35
36
37
38
39
# File 'lib/qas/archive.rb', line 30

def archive
  require 'git'

  Utils.spin(project.name) do
    repo = Git.open project.folder
    repo.archive repo.current_branch, @fullpath, format: @format # TODO: fiber/multithread
  end

  puts # a bit more of space
end

#infoObject



47
48
49
# File 'lib/qas/archive.rb', line 47

def info
  print "#{project.name} > #{@fullpath}"
end

#mkfolderObject

create archived folder



42
43
44
45
# File 'lib/qas/archive.rb', line 42

def mkfolder
  require 'fileutils'
  FileUtils.mkdir_p ARCHIVED unless ARCHIVED.exist?
end

#runObject



51
52
53
54
55
56
57
# File 'lib/qas/archive.rb', line 51

def run
  return unless names.include? project.name

  mkfolder
  info
  archive
end