Class: Kiip::Repository::Package

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(path) ⇒ Object



11
12
13
# File 'lib/kiip/repository/package.rb', line 11

def decode path
  Base64.decode64 path
end

.encode(path) ⇒ Object



7
8
9
# File 'lib/kiip/repository/package.rb', line 7

def encode path
  Base64.encode64 path
end

Instance Method Details

#contentString[]

Returns array of package content files/folders.

Returns:

  • (String[])

    array of package content files/folders



84
85
86
# File 'lib/kiip/repository/package.rb', line 84

def content
  Pathname.new(path).children.map(&:basename).map(&:to_s)
end

#create!Object

creates the package or raises an error



66
67
68
# File 'lib/kiip/repository/package.rb', line 66

def create!
  Dir.mkdir(path)
end

#decoded_contentObject



61
62
63
# File 'lib/kiip/repository/package.rb', line 61

def decoded_content
  content.map { |s| self.class.decode s }
end

#exists?boolean

Returns:

  • (boolean)


75
76
77
# File 'lib/kiip/repository/package.rb', line 75

def exists?
  File.directory?(path)
end

#pathObject



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

def path
  File.join(repository.path, name)
end

#restoreObject



20
21
22
23
24
25
26
27
# File 'lib/kiip/repository/package.rb', line 20

def restore
  unlink
  content.each do |encoded_orginal_path|
    decoded_original_path = self.class.decode encoded_orginal_path
    FileUtils.cp_r(File.join(path, encoded_orginal_path), decoded_original_path,
                   verbose: repository.is_verbose, noop: repository.is_dry)
  end
end

#rmObject



70
71
72
# File 'lib/kiip/repository/package.rb', line 70

def rm
  FileUtils.rm_r(path, verbose: repository.is_verbose, noop: repository.is_dry)
end

#sync!Object



53
54
55
56
57
58
59
# File 'lib/kiip/repository/package.rb', line 53

def sync!
  content.each do |subpath|
    source = self.class.decode subpath
    task = Tasks::SymlinkTask.new(name: 'task-name', source: source, target: File.join(path, subpath))
    task.exec!
  end
end

#track(tracking_path) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kiip/repository/package.rb', line 39

def track(tracking_path)
  raise "path does not exist: #{tracking_path}" unless File.exists?(File.expand_path tracking_path)

  tracking_path = tracking_path.gsub %r{^#{File.expand_path('~')}}, '~'

  # escape /
  escaped_tracking_path = self.class.encode tracking_path

  return if repository.is_dry

  task = Tasks::SymlinkTask.new(name: 'task-name', source: tracking_path, target: File.join(path, escaped_tracking_path))
  task.exec!
end

removes the links to the package content



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

def unlink
  content.each do |encoded_orginal_path|
    decoded_original_path = self.class.decode encoded_orginal_path
    if File.symlink?(decoded_original_path) and File.readlink(decoded_original_path) == File.join(path, encoded_orginal_path)
      FileUtils.rm decoded_original_path
    end
  end
end