Class: Kiip::Package
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Kiip::Package
- Includes:
- Hashie::Extensions::Dash::Coercion
- Defined in:
- lib/kiip/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
- #entries ⇒ 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
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
#content ⇒ String[]
Returns 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_content ⇒ Object
60 61 62 |
# File 'lib/kiip/package.rb', line 60 def decoded_content content.map { |s| self.class.decode s } end |
#entries ⇒ Object
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
74 75 76 |
# File 'lib/kiip/package.rb', line 74 def exists? File.directory?(path) end |
#path ⇒ Object
78 79 80 |
# File 'lib/kiip/package.rb', line 78 def path File.join(repository.path, name) end |
#restore ⇒ Object
29 30 31 |
# File 'lib/kiip/package.rb', line 29 def restore entries.each &:restore end |
#rm ⇒ Object
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. 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 |
#unlink ⇒ Object
removes the links to the package content
34 35 36 |
# File 'lib/kiip/package.rb', line 34 def unlink entries.each &:unlink end |