Class: Ubalo::PodDir

Inherits:
Object
  • Object
show all
Defined in:
lib/ubalo/pod_dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PodDir



9
10
11
# File 'lib/ubalo/pod_dir.rb', line 9

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathObject (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

Raises:



85
86
87
# File 'lib/ubalo/pod_dir.rb', line 85

def assert_not_empty!
  raise Ubalo::Error, "no files to push" if manifest.empty?
end

#default_filesObject



49
50
51
52
53
54
55
56
57
# File 'lib/ubalo/pod_dir.rb', line 49

def default_files
  gem_root = File.expand_path("../../..", __FILE__)
  files_root = File.join(gem_root, "resources/init_files")
  files = {}
  %w{.ubaloignore}.each do |filename|
    files[filename] = File.read(File.join(files_root, filename))
  end
  files
end

#extract_archive(archive_name) ⇒ Object



78
79
80
81
82
83
# File 'lib/ubalo/pod_dir.rb', line 78

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



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ubalo/pod_dir.rb', line 35

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



13
14
15
16
17
# File 'lib/ubalo/pod_dir.rb', line 13

def inited?
  in_path do
    File.exist?("Ubalopod")
  end
end

#inspectObject



89
90
91
# File 'lib/ubalo/pod_dir.rb', line 89

def inspect
  "#<PodDir path=#{path.inspect}>"
end

#make_archive(archive_name) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/ubalo/pod_dir.rb', line 70

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

#manifestObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/ubalo/pod_dir.rb', line 59

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

#nameObject



19
20
21
22
23
24
25
# File 'lib/ubalo/pod_dir.rb', line 19

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

#write_name(name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/ubalo/pod_dir.rb', line 27

def write_name(name)
  in_path do
    File.open("Ubalopod", "w") do |f|
      f.puts name
    end
  end
end