Class: Ubalo::PodDir
- Inherits:
-
Object
- Object
- Ubalo::PodDir
- Defined in:
- lib/ubalo/pod_dir.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #assert_not_empty! ⇒ Object
- #default_files ⇒ Object
- #extract_archive(archive_name) ⇒ Object
- #init(name, logger) ⇒ Object
- #inited? ⇒ Boolean
-
#initialize(path) ⇒ PodDir
constructor
A new instance of PodDir.
- #inspect ⇒ Object
- #make_archive(archive_name) ⇒ Object
- #manifest ⇒ Object
- #name ⇒ Object
- #v2? ⇒ Boolean
- #write_name(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ PodDir
Returns a new instance of PodDir.
9 10 11 |
# File 'lib/ubalo/pod_dir.rb', line 9 def initialize(path) @path = File.(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ubalo/pod_dir.rb', line 7 def path @path end |
Instance Method Details
#assert_not_empty! ⇒ Object
89 90 91 |
# File 'lib/ubalo/pod_dir.rb', line 89 def assert_not_empty! raise Ubalo::Error, "no files to push" if manifest.empty? end |
#default_files ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/ubalo/pod_dir.rb', line 53 def default_files gem_root = File.("../../..", __FILE__) files_root = File.join(gem_root, "resources/init_files") files = {} %w{.ubaloignore run.sh}.each do |filename| files[filename] = File.read(File.join(files_root, filename)) end files end |
#extract_archive(archive_name) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/ubalo/pod_dir.rb', line 82 def extract_archive archive_name in_path do archive = Zlib::GzipReader.new(File.open(archive_name, 'rb')) Archive::Tar::Minitar.unpack(archive, ".") end end |
#init(name, logger) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ubalo/pod_dir.rb', line 39 def init(name, logger) write_name(name) in_path do default_files.each do |filename,content| if File.exist?(filename) logger.puts "Using existing #{filename.inspect}" else logger.puts "Writing an example #{filename.inspect}" File.open(filename, "w"){|f| f.write(content)} end end end end |
#inited? ⇒ Boolean
17 18 19 20 21 |
# File 'lib/ubalo/pod_dir.rb', line 17 def inited? in_path do File.exist?("Ubalopod") end end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/ubalo/pod_dir.rb', line 93 def inspect "#<PodDir path=#{path.inspect}>" end |
#make_archive(archive_name) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ubalo/pod_dir.rb', line 74 def make_archive archive_name in_path do assert_not_empty! archive = Zlib::GzipWriter.new(File.open(archive_name, 'wb')) Archive::Tar::Minitar.pack(manifest, archive) end end |
#manifest ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ubalo/pod_dir.rb', line 63 def manifest in_path do Dir.glob('{.**,**}').map do |path| next if ignore_patterns.any? do |pattern| File.fnmatch?(pattern, path, File::FNM_DOTMATCH) end path end.compact end end |
#name ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/ubalo/pod_dir.rb', line 23 def name in_path do File.read("Ubalopod").strip end rescue Errno::ENOENT raise Ubalo::Error, "Please run this command from a pod directory" end |
#v2? ⇒ Boolean
13 14 15 |
# File 'lib/ubalo/pod_dir.rb', line 13 def v2? inited? && manifest.include?(".ubalov2") end |
#write_name(name) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ubalo/pod_dir.rb', line 31 def write_name(name) in_path do File.open("Ubalopod", "w") do |f| f.puts name end end end |