Class: Kiip::Repository::Package
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Kiip::Repository::Package
- Includes:
- Hashie::Extensions::Dash::Coercion
- Defined in:
- lib/kiip/repository/package.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#content ⇒ String[]
Array of package content files/folders.
-
#create! ⇒ Object
creates the package or raises an error.
- #decoded_content ⇒ Object
- #exists? ⇒ boolean
- #path ⇒ Object
- #restore ⇒ Object
- #rm ⇒ Object
- #sync! ⇒ Object
- #track(tracking_path) ⇒ Object
-
#unlink ⇒ Object
removes the links to the package content.
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
#content ⇒ String[]
Returns 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_content ⇒ Object
61 62 63 |
# File 'lib/kiip/repository/package.rb', line 61 def decoded_content content.map { |s| self.class.decode s } end |
#exists? ⇒ boolean
75 76 77 |
# File 'lib/kiip/repository/package.rb', line 75 def exists? File.directory?(path) end |
#path ⇒ Object
79 80 81 |
# File 'lib/kiip/repository/package.rb', line 79 def path File.join(repository.path, name) end |
#restore ⇒ Object
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 |
#rm ⇒ Object
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. tracking_path) tracking_path = tracking_path.gsub %r{^#{File.('~')}}, '~' # 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 |
#unlink ⇒ Object
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 |