Module: Hbc::Metadata

Included in:
Cask
Defined in:
Library/Homebrew/cask/lib/hbc/metadata.rb

Constant Summary collapse

METADATA_SUBDIR =
".metadata".freeze

Instance Method Summary collapse

Instance Method Details

#metadata_master_container_pathObject



5
6
7
# File 'Library/Homebrew/cask/lib/hbc/metadata.rb', line 5

def 
  @metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR)
end

#metadata_subdir(leaf, version: self.version, timestamp: :latest, create: false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'Library/Homebrew/cask/lib/hbc/metadata.rb', line 39

def (leaf, version: self.version, timestamp: :latest, create: false)
  if create && timestamp == :latest
    raise CaskError, "Cannot create metadata subdir when timestamp is :latest."
  end

  unless leaf.respond_to?(:empty?) && !leaf.empty?
    raise CaskError, "Cannot create metadata subdir for empty leaf."
  end

  parent = (version: version, timestamp: timestamp, create: create)

  return nil if parent.nil?

  subdir = parent.join(leaf)

  if create && !subdir.directory?
    odebug "Creating metadata subdirectory #{subdir}."
    subdir.mkpath
  end

  subdir
end

#metadata_timestamped_path(version: self.version, timestamp: :latest, create: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'Library/Homebrew/cask/lib/hbc/metadata.rb', line 19

def (version: self.version, timestamp: :latest, create: false)
  if create && timestamp == :latest
    raise CaskError, "Cannot create metadata path when timestamp is :latest."
  end

  path = if timestamp == :latest
    Pathname.glob((version: version).join("*")).sort.last
  else
    timestamp = new_timestamp if timestamp == :now
    (version: version).join(timestamp)
  end

  if create && !path.directory?
    odebug "Creating metadata directory #{path}."
    path.mkpath
  end

  path
end

#metadata_versioned_path(version: self.version) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'Library/Homebrew/cask/lib/hbc/metadata.rb', line 9

def (version: self.version)
  cask_version = (version || :unknown).to_s

  if cask_version.empty?
    raise CaskError, "Cannot create metadata path with empty version."
  end

  .join(cask_version)
end