Class: RepoMate::Link

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

Overview

Class containing the main logic

Instance Method Summary collapse

Constructor Details

#initializeLink

Init



10
11
12
13
# File 'lib/repomate/link.rb', line 10

def initialize
  @repository = Repository.new
  @metafile   = Metafile.new
end

Instance Method Details

#cleanupObject

cleans up unused directories



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/repomate/link.rb', line 54

def cleanup
  action = false

  @repository.categories.each do |category|
    next if category.eql?("stage")
    Architecture.dataset(category).each do |entry|
      directory = Architecture.new(entry[:architecture], entry[:component], entry[:suitename], category)
      if directory.is_unused?(entry[:fullpath])
        action = true
        directory.destroy
      end
    end
    Component.dataset(category).each do |entry|
      directory = Component.new(entry[:component], entry[:suitename], category)
      if directory.is_unused?(entry[:fullpath])
        action = true
        directory.destroy
      end
    end
    Suite.dataset(category).each do |entry|
      directory = Suite.new(entry[:suitename], category)
      if directory.is_unused?(entry[:fullpath])
        action = true
        directory.destroy
      end
    end
  end
  
  @metafile.create if action
end

#create(workload) ⇒ Object

links the workload



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/repomate/link.rb', line 21

def create(workload)
  workload.each do |entry|
    @repository.create(entry[:suitename], entry[:component], entry[:architecture])

    unless File.exists?(entry[:destination_fullname])
      package = Package.new(entry[:source_fullname], entry[:suitename], entry[:component])
      
      package.create_checksums

      File.symlink(entry[:source_fullname], entry[:destination_fullname])
      puts "Package: #{package.newbasename} linked to production => #{entry[:suitename]}/#{entry[:component]}"
    end
  end
end

#destroy(workload) ⇒ Object

unlinks workload



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/repomate/link.rb', line 37

def destroy(workload)
  workload.each do |entry|
    package = Package.new(entry[:destination_fullname], entry[:suitename], entry[:component])
    package.delete_checksums

    if File.exists?(entry[:destination_fullname])
      File.unlink(entry[:destination_fullname])
      puts "Package: #{package.newbasename} unlinked from #{entry[:category]} => #{entry[:suitename]}/#{entry[:component]}"
    else
      puts "Package: #{package.newbasename} was not linked"
    end
  end
  
  cleanup unless workload.empty?
end

#exist?(fullname) ⇒ Boolean

Checks if file exists

Returns:

  • (Boolean)


16
17
18
# File 'lib/repomate/link.rb', line 16

def exist?(fullname)
  File.exists?(fullname)
end