Class: GitDump::Version::Builder

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/git_dump/version/builder.rb

Overview

Creating version

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#[], #each, #each_recursive

Constructor Details

#initialize(repo) ⇒ Builder

Returns a new instance of Builder.



14
15
16
17
18
19
# File 'lib/git_dump/version/builder.rb', line 14

def initialize(repo)
  fail ArgumentError, 'Expected Repo' unless repo.is_a?(Repo)

  @repo = repo
  @tree = Tree::Builder.new(repo, nil, nil)
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



13
14
15
# File 'lib/git_dump/version/builder.rb', line 13

def repo
  @repo
end

Instance Method Details

#commit(options = {}) ⇒ Object

Create commit and tag it, returns Version instance Options:

:time - set version time (tag and commit)
:tags - list of strings to associate with this version
:annotation - tag message
:description - commit message
:keep_identity - don't override identity with "git_dump

gitdump@hostname“



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git_dump/version/builder.rb', line 41

def commit(options = {})
  options = {:time => Time.now}.merge(options)

  base = {:time => options[:time]}
  unless options[:keep_identity]
    base[:name] = 'git_dump'
    base[:email] = "git_dump@#{GitDump.hostname}"
  end

  commit_sha = repo.commit(tree.sha, base.merge({
    :message => options[:description],
  }))

  tag_name = repo.tag(commit_sha, name_parts(options), base.merge({
    :message => options[:annotation],
  }))

  repo.gc(:auto => true)

  Version.by_id(repo, tag_name)
end

#inspectObject



63
64
65
# File 'lib/git_dump/version/builder.rb', line 63

def inspect
  "#<#{self.class} tree=#{tree.inspect}>"
end

#store(path, content, mode = 0o644) ⇒ Object Also known as: []=

Store data ‘content` with mode `mode` at `path` Pass `nil` as content to remove



23
24
25
# File 'lib/git_dump/version/builder.rb', line 23

def store(path, content, mode = 0o644)
  tree.store(path, content, mode)
end

#store_from(path, from, mode = nil) ⇒ Object

Store data from ‘from` with mode `mode` (by default file mode) at `path`



29
30
31
# File 'lib/git_dump/version/builder.rb', line 29

def store_from(path, from, mode = nil)
  tree.store_from(path, from, mode)
end