Class: Giblish::GitSummaryDataProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/gitrepos/gitsummaryprovider.rb

Defined Under Namespace

Classes: BranchInfo, CommitInfo, TagInfo

Constant Summary collapse

DEFAULT_GIT_SUMMARY_TEMPLATE =
"/gitsummary.erb"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name) ⇒ GitSummaryDataProvider

Returns a new instance of GitSummaryDataProvider.



18
19
20
21
22
23
24
25
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 18

def initialize(repo_name)
  @index_basename = "index"

  # all these are used by erb
  @repo_name = repo_name
  @branch_info = []
  @tag_infos = []
end

Instance Attribute Details

#branchesObject (readonly)

Returns the value of attribute branches.



5
6
7
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 5

def branches
  @branches
end

#index_basenameObject

Returns the value of attribute index_basename.



6
7
8
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 6

def index_basename
  @index_basename
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 5

def tags
  @tags
end

Instance Method Details

#cache_info(repo, treeish) ⇒ Object

Cache info on one tag or branch

repo

a handle to a Git repo object

treeish

either a Git::Tag or a Git::Branch object



31
32
33
34
35
36
37
38
39
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 31

def cache_info(repo, treeish)
  if treeish.respond_to?(:tag?) && treeish.tag?
    @tag_infos.push(
      cache_tag_info(repo, treeish)
    ).sort_by!(&:date).reverse!
  else
    @branch_info.push(cache_branch_info(repo, treeish))
  end
end

#index_path(treeish_name) ⇒ Object

returns

a string with the relative path to the index file in the given branch/tag subtree



43
44
45
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 43

def index_path(treeish_name)
  Giblish.to_fs_str(treeish_name) + "/" + @index_basename + ".adoc"
end

#sourceObject



47
48
49
50
# File 'lib/giblish/gitrepos/gitsummaryprovider.rb', line 47

def source
  erb_template = File.read(__dir__ + DEFAULT_GIT_SUMMARY_TEMPLATE)
  ERB.new(erb_template, trim_mode: "<>").result(binding)
end