Class: Cartage::Manifest

Inherits:
Plugin
  • Object
show all
Defined in:
lib/cartage/manifest.rb,
lib/cartage/manifest/commands.rb

Overview

Manage and use the package manifest ('Manifest.txt') and the ignore file ('.cartignore').

Defined Under Namespace

Modules: HandleMissingManifest Classes: CheckCommand, InstallDefaultIgnoreCommand, ManifestCommand, ShowCommand

Constant Summary collapse

MissingError =

This exception is raised if the package manifest is missing.

Class.new(StandardError) do
  def message
    <<-exception
Cartage cannot create a package without a Manifest.txt file. You may generate
or update the Manifest.txt file with the following command:

    exception
  end
end
DIFF =

:nodoc:

if system('gdiff', __FILE__, __FILE__) #:nodoc:
  'gdiff'
else
  'diff'
end

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

decorate, inherited, load, registered

Constructor Details

#initialize(cartage) ⇒ Manifest

:nodoc:


22
23
24
# File 'lib/cartage/manifest.rb', line 22

def initialize(cartage) #:nodoc:
  @cartage = cartage
end

Class Method Details

.commandsObject

:nodoc:


96
97
98
99
100
101
102
103
# File 'lib/cartage/manifest/commands.rb', line 96

def self.commands #:nodoc:
  [
    ManifestCommand,
    CheckCommand,
    InstallDefaultIgnoreCommand,
    ShowCommand
  ]
end

Instance Method Details

#checkObject

Checks Manifest.txt


67
68
69
70
71
72
73
74
# File 'lib/cartage/manifest.rb', line 67

def check
  raise MissingError unless manifest_file.exist?
  tmp = create_file_list('Manifest.tmp')
  system(DIFF, '-du', manifest_file.basename.to_s, tmp.to_s)
  $?.success?
ensure
  tmp.unlink if tmp
end

#generateObject

Generates Manifest.txt.


62
63
64
# File 'lib/cartage/manifest.rb', line 62

def generate
  create_file_list(manifest_file)
end

#install_default_ignore(mode: nil) ⇒ Object

Installs the default .cartignore file.


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cartage/manifest.rb', line 77

def install_default_ignore(mode: nil)
  mode = mode.to_s.downcase.strip
  save = mode || !ignore_file.exist?

  if mode == :merge
    data = strip_comments_and_empty_lines(ignore_file.readlines)

    if data.empty?
      data = DEFAULT_IGNORE
    else
      data += strip_comments_and_empty_lines(DEFAULT_IGNORE.split($/))
      data = data.uniq.join("\n")
    end
  else
    data = DEFAULT_IGNORE
  end

  ignore_file.open('w') { |f| f.puts data } if save
end

#resolve(path = nil, command: nil) ⇒ Object

Resolve the Manifest to something that can be used by tar -T. The manifest should be relative to the files in the repository, as reported from git ls-files. tar requires either full paths, or files relative to the directory you are packaging from (and we want relative files).

This reads the manifest, prunes it with package ignores, and then writes it in a GNU tar compatible format as a tempfile. It does this by taking the expanded version of path, grabbing the basename, and inserting that in front of every line in the Manifest.

If path is not provided, Dir.pwd is used.


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cartage/manifest.rb', line 38

def resolve(path = nil, command: nil) # :yields: resolved manifest filename
  raise MissingError unless manifest_file.exist?

  data = strip_comments_and_empty_lines(manifest_file.readlines)
  raise "Manifest.txt is empty." if data.empty?

  path = Pathname(path || Dir.pwd).expand_path.basename
  tmpfile = Tempfile.new('Manifest')

  tmpfile.puts prune(data, with_slugignore: true).map { |line|
    path.join(line).to_s
  }.join("\n")

  tmpfile.close

  yield tmpfile.path
ensure
  if tmpfile
    tmpfile.close
    tmpfile.unlink
  end
end