Class: Kiip::Repository
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Kiip::Repository
- Includes:
- Hashie::Extensions::Dash::PropertyTranslation
- Defined in:
- lib/kiip/repository.rb,
lib/kiip/repository/package.rb
Defined Under Namespace
Classes: Package
Constant Summary collapse
- ID_FILE_NAME =
'.kiip_repository'
Class Method Summary collapse
Instance Method Summary collapse
- #create! ⇒ Object
- #exists? ⇒ Boolean
- #packages ⇒ Object
-
#print_content ⇒ String
Multi-line string with content of the repository.
- #rm(*package_names) ⇒ Object
- #sync!(*names) ⇒ Object
- #track(package_name, path) ⇒ Object
Class Method Details
.get_instance(**options) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/kiip/repository.rb', line 8 def self.get_instance(**) path = ENV['KIIP_REPO'] || raise('KIIP_REPO environment variable not defined') [:path] = path return self.new(**) end |
Instance Method Details
#create! ⇒ Object
56 57 58 59 |
# File 'lib/kiip/repository.rb', line 56 def create! FileUtils.mkdir_p(path) FileUtils.touch(File.join(path, ID_FILE_NAME)) end |
#exists? ⇒ Boolean
21 22 23 24 |
# File 'lib/kiip/repository.rb', line 21 def exists? id_file_path = File.join(path, ID_FILE_NAME) File.exists? id_file_path end |
#packages ⇒ Object
50 51 52 53 54 |
# File 'lib/kiip/repository.rb', line 50 def packages package_names.map do |package_name| get_package(package_name) end end |
#print_content ⇒ String
Returns multi-line string with content of the repository.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kiip/repository.rb', line 39 def print_content StringIO.open do |result| packages.each do |package| result.puts package.name + ':' package.decoded_content.each { |content| result.puts ' ' + content } end result.string end end |
#rm(*package_names) ⇒ Object
61 62 63 64 65 |
# File 'lib/kiip/repository.rb', line 61 def rm *package_names package_names.each do |package_name| get_package(package_name).rm end end |
#sync!(*names) ⇒ Object
26 27 28 29 |
# File 'lib/kiip/repository.rb', line 26 def sync! *names names = package_names if names.empty? names.each { |name| get_package(name).sync! } end |
#track(package_name, path) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/kiip/repository.rb', line 31 def track package_name, path return unless ensure_existance package = get_package(package_name) package.create! unless package.exists? package.track(path) end |