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

#create!Object

creates the package or raises an error



48
49
50
# File 'lib/kiip/repository/package.rb', line 48

def create!
  Dir.mkdir(path)
end

#decoded_contentObject



43
44
45
# File 'lib/kiip/repository/package.rb', line 43

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

#exists?boolean

Returns:

  • (boolean)


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

def exists?
  File.directory?(path)
end

#pathObject



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

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

#rmObject



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

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

#sync!Object



35
36
37
38
39
40
41
# File 'lib/kiip/repository/package.rb', line 35

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



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kiip/repository/package.rb', line 21

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