Class: Kiip::Package

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(path) ⇒ Object



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

def decode path
  Base64.decode64 path
end

.encode(path) ⇒ Object



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

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



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

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

#create!Object

creates the package or raises an error



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

def create!
  Dir.mkdir(path)
end

#decoded_contentObject



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

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

#entriesObject



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

def entries
  content.map do |encoded_original_path|
    Entry.new(
        source: self.class.decode(encoded_original_path),
        target: File.join(path, encoded_original_path),
        package: self
    )
  end
end

#exists?boolean

Returns:

  • (boolean)


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

def exists?
  File.directory?(path)
end

#pathObject



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

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

#restoreObject



29
30
31
# File 'lib/kiip/package.rb', line 29

def restore
  entries.each &:restore
end

#rmObject



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

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

#sync!Object



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

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), is_verbose: repository.is_verbose, is_dry: repository.is_dry)
    task.exec!
  end
end

#track(tracking_path) ⇒ Object



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

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), is_verbose: repository.is_verbose, is_dry: repository.is_dry)
  task.exec!
end

removes the links to the package content



34
35
36
# File 'lib/kiip/package.rb', line 34

def unlink
  entries.each &:unlink
end