Class: Kiip::Repository

Inherits:
Hashie::Dash
  • Object
show all
Includes:
Hashie::Extensions::Dash::PropertyTranslation
Defined in:
lib/kiip/repository.rb,
lib/kiip/repository/package.rb

Defined Under Namespace

Classes: Package

Constant Summary collapse

ID_FILE_NAME =
'.kiip_repository'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_instance(**options) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/kiip/repository.rb', line 8

def self.get_instance(**options)
  path = ENV['KIIP_REPO'] || raise('KIIP_REPO environment variable not defined')

  options[:path] = path

  return self.new(**options)
end

Instance Method Details

#create!Object



85
86
87
88
# File 'lib/kiip/repository.rb', line 85

def create!
  FileUtils.mkdir_p(path)
  FileUtils.touch(File.join(path, ID_FILE_NAME))
end

#exists?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/kiip/repository.rb', line 21

def exists?
  id_file_path = File.join(path, ID_FILE_NAME)
  File.exists? id_file_path
end

#packagesObject



79
80
81
82
83
# File 'lib/kiip/repository.rb', line 79

def packages
  package_names.map do |package_name|
    get_package(package_name)
  end
end

Returns multi-line string with content of the repository.

Returns:

  • (String)

    multi-line string with content of the repository



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kiip/repository.rb', line 51

def print_content
  StringIO.open do |result|
    packages.each do |package|
      result.puts package.name + ':'
      package.content.each do |content|
        decoded_path_original = Kiip::Repository::Package.decode(content)
        decoded_path_expanded = File.expand_path decoded_path_original

        if File.symlink?(decoded_path_expanded)
          status = File.readlink(decoded_path_expanded) == File.join(package.path, content) ? 'linked' : 'symlink'
        elsif File.directory?(decoded_path_expanded)
          status = 'directory'
        elsif File.file? decoded_path_expanded
          status = 'file'
        elsif not File.exist? decoded_path_expanded
          status = 'not existant'
        else
          raise 'unknown status'
        end

        result.puts "  #{decoded_path_original} | #{status}"
      end
    end

    result.string
  end
end

#restore(*package_names) ⇒ Object



32
33
34
35
36
# File 'lib/kiip/repository.rb', line 32

def restore *package_names
  package_names.each do |name|
    get_package(name).restore
  end
end

#rm(*package_names) ⇒ Object



90
91
92
93
94
# File 'lib/kiip/repository.rb', line 90

def rm *package_names
  package_names.each do |package_name|
    get_package(package_name).rm
  end
end

#sync!(*names) ⇒ Object



38
39
40
41
# File 'lib/kiip/repository.rb', line 38

def sync! *names
  names = package_names if names.empty?
  names.each { |name| get_package(name).sync! }
end

#track(package_name, path) ⇒ Object



43
44
45
46
47
48
# File 'lib/kiip/repository.rb', line 43

def track package_name, path
  return unless ensure_existance
  package = get_package(package_name)
  package.create! unless package.exists?
  package.track(path)
end


26
27
28
29
30
# File 'lib/kiip/repository.rb', line 26

def unlink *package_names
  package_names.each do |name|
    get_package(name).unlink
  end
end