Class: GitCache::RepoInfo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/git_cache/repo_info.rb

Overview

Information about a remote git repository in the cache.

This object is returned from #repo_info.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_dirString (readonly)

The base directory of this git repository's cache entry. This directory contains all cached data related to this repo. Deleting it effectively removes the repo from the cache.

Returns:

  • (String)


19
20
21
# File 'lib/git_cache/repo_info.rb', line 19

def base_dir
  @base_dir
end

#last_accessedTime? (readonly)

The last time any cached data from this repo was accessed, or nil if the information is unavailable.

Returns:

  • (Time, nil)


34
35
36
# File 'lib/git_cache/repo_info.rb', line 34

def last_accessed
  @last_accessed
end

#remoteString (readonly)

The git remote, usually a file system path or URL.

Returns:

  • (String)


26
27
28
# File 'lib/git_cache/repo_info.rb', line 26

def remote
  @remote
end

Instance Method Details

#<=>(other) ⇒ Integer

Comparison function

Parameters:

Returns:

  • (Integer)


89
90
91
# File 'lib/git_cache/repo_info.rb', line 89

def <=>(other)
  remote <=> other.remote
end

#refs(ref: nil) ⇒ Array<RefInfo>

A list of git refs (branches, tags, shas) that have been accessed from this repo.

Parameters:

  • ref (String, nil) (defaults to: nil)

    If provided, return only entries matching this ref name. If omitted, return all entries.

Returns:



44
45
46
47
# File 'lib/git_cache/repo_info.rb', line 44

def refs(ref: nil)
  return @refs.dup if ref.nil?
  @refs.find_all { |elem| elem.ref == ref }
end

#sources(sha: nil, git_path: nil) ⇒ Array<SourceInfo>

A list of shared source files and directories accessed for this repo.

Parameters:

  • sha (String, nil) (defaults to: nil)

    If provided, return only entries matching this SHA. If omitted, entries for all SHAs are included.

  • git_path (String, nil) (defaults to: nil)

    If provided, return only entries matching this git path. If omitted, entries for all paths are included.

Returns:



59
60
61
62
63
64
65
# File 'lib/git_cache/repo_info.rb', line 59

def sources(sha: nil, git_path: nil)
  return @sources.dup if sha.nil? && git_path.nil?
  @sources.find_all do |elem|
    (sha.nil? || elem.sha == sha) &&
      (git_path.nil? || elem.git_path == git_path)
  end
end

#to_hHash

Convert this RepoInfo to a hash suitable for JSON output

Returns:

  • (Hash)


72
73
74
75
76
77
78
79
80
81
# File 'lib/git_cache/repo_info.rb', line 72

def to_h
  result = {
    "remote" => remote,
    "base_dir" => base_dir,
  }
  result["last_accessed"] = last_accessed.to_i if last_accessed
  result["refs"] = refs.map(&:to_h)
  result["sources"] = sources.map(&:to_h)
  result
end