Class: HackerSlides::Bundle
- Inherits:
-
Object
- Object
- HackerSlides::Bundle
- Defined in:
- lib/hacker_slides/bundle.rb
Class Method Summary collapse
- .builtin_bundle_dir ⇒ Object
- .cache_dir ⇒ Object
- .extract_files_from_bundle(bundle, files, dest) ⇒ Object
-
.install(src, bundle) ⇒ Object
install remote/local bundle.
- .list_bundles ⇒ Object
- .load_manifest(bundle) ⇒ Object
- .lookup_bundle_path(bundle_name) ⇒ Object
- .usr_bundle_dir ⇒ Object
Class Method Details
.builtin_bundle_dir ⇒ Object
47 48 49 |
# File 'lib/hacker_slides/bundle.rb', line 47 def builtin_bundle_dir return File.(File.dirname(__FILE__) + '/../../bundles') end |
.cache_dir ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hacker_slides/bundle.rb', line 69 def cache_dir if(PLATFORM =~ /win32/) dir = File.join(ENV['USERPROFILE'], '.hackerslides') else dir = File.join(File.("~"), ".hackerslides") end unless File.exist?(dir) FileUtils.mkdir(dir) end return dir end |
.extract_files_from_bundle(bundle, files, dest) ⇒ Object
82 83 84 85 86 |
# File 'lib/hacker_slides/bundle.rb', line 82 def extract_files_from_bundle(bundle, files, dest) Zlib::GzipReader.open(bundle) do |tgz| Archive::Tar::Minitar.unpack(tgz, dest, files) end end |
.install(src, bundle) ⇒ Object
install remote/local bundle
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hacker_slides/bundle.rb', line 13 def install(src, bundle) bundle = "#{bundle}.bundle" if(File.extname(bundle) != '.bundle') if(src) bundle_path = File.join(src, bundle) else bundle_path = File.(bundle) end dest = File.join(usr_bundle_dir, bundle) open(bundle_path) do |stream| File.open(dest, 'wb') do |f| f.write(stream.read) end end end |
.list_bundles ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hacker_slides/bundle.rb', line 31 def list_bundles builtin_bundles = [] usr_bundles = [] Dir.glob(File.join(usr_bundle_dir, '*')).each do |bundle| bundle_name = File.basename(bundle, '.*') usr_bundles << bundle_name end Dir.glob(File.join(builtin_bundle_dir, '*')).each do |bundle| bundle_name = File.basename(bundle, '.*') builtin_bundles << bundle_name end return builtin_bundles, usr_bundles end |
.load_manifest(bundle) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hacker_slides/bundle.rb', line 88 def load_manifest(bundle) Zlib::GzipReader.open(bundle) do |tgz| Archive::Tar::Minitar::Input.open(tgz) do |stream| stream.each do |entry| if(entry.name == 'MANIFEST') manifest = [] entry.read.split(/\n/).each_with_index do |line,i| case line when /^\s*$/ # skip empty lines when /^\s*#.*$/ # skip comment lines else manifest << line.strip end end return manifest end end end end return nil end |
.lookup_bundle_path(bundle_name) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/hacker_slides/bundle.rb', line 59 def lookup_bundle_path(bundle_name) bundle = File.join(usr_bundle_dir, "#{bundle_name}.bundle") if(File.exists?(bundle)) return bundle else bundle = File.join(builtin_bundle_dir, "#{bundle_name}.bundle") return bundle if(File.exists?(bundle)) end end |
.usr_bundle_dir ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/hacker_slides/bundle.rb', line 51 def usr_bundle_dir bundle_dir = File.join(cache_dir, 'bundles') unless File.exists?(bundle_dir) FileUtils.mkdir(bundle_dir) end return bundle_dir end |