Class: MultiGit::Commit::Builder
- Inherits:
-
Object
- Object
- MultiGit::Commit::Builder
- Extended by:
- Forwardable
- Defined in:
- lib/multi_git/commit.rb
Overview
A commit builder helps creating new commits by providing a simple interface, sane defaults and some validations.
You can create a new commit using the commit builder like this:
Instance Attribute Summary collapse
- #author ⇒ Handle
- #commit_time ⇒ Time
- #committer ⇒ Handle
- #message(*args) ⇒ String
- #parents ⇒ Array<Commit::Base> readonly
- #time ⇒ Time
Instance Method Summary collapse
- #>>(repo) ⇒ Object
- #[]=(path, content) ⇒ Object
- #at(time) ⇒ Object
-
#by(handle) ⇒ Object
DSL method to set author and committer in one step.
-
#initialize(from = nil, &block) ⇒ Builder
constructor
A new instance of Builder.
- #tree { ... } ⇒ Tree::Builder
Methods included from Base
Methods included from Utils::AbstractMethods
Methods included from Builder
Constructor Details
#initialize(from = nil, &block) ⇒ Builder
Returns a new instance of Builder.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/multi_git/commit.rb', line 152 def initialize(from = nil, &block) @parents = [] if from.kind_of? Tree @tree = from.to_builder elsif from.kind_of? Tree::Builder @tree = from elsif from.kind_of? Commit @tree = from.tree.to_builder @parents << from elsif from.nil? @tree = Tree::Builder.new end @author = nil @committer = nil @time = @commit_time = Time.now instance_eval(&block) if block end |
Instance Attribute Details
#commit_time ⇒ Time
102 103 104 |
# File 'lib/multi_git/commit.rb', line 102 def commit_time @commit_time end |
#committer ⇒ Handle
107 108 109 |
# File 'lib/multi_git/commit.rb', line 107 def committer @committer end |
#message(*args) ⇒ String
80 81 82 83 84 85 86 87 |
# File 'lib/multi_git/commit.rb', line 80 def (*args) if args.any? self. = args.first return self else return @message end end |
#parents ⇒ Array<Commit::Base> (readonly)
97 98 99 |
# File 'lib/multi_git/commit.rb', line 97 def parents @parents end |
#time ⇒ Time
100 101 102 |
# File 'lib/multi_git/commit.rb', line 100 def time @time end |
Instance Method Details
#>>(repo) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/multi_git/commit.rb', line 170 def >>(repo) new_tree = repo << tree new_parents = parents.map{|p| repo.write(p).oid } c = committer || || Handle::DEFAULT a = || committer || Handle::DEFAULT return repo.make_commit( :time => time, :author => a, :commit_time => commit_time, :committer => c, :parents => new_parents, :tree => new_tree.oid, :message => || "Thank you for using multi_git", :update_ref => [] ) end |
#at(time) ⇒ Object
142 143 144 145 |
# File 'lib/multi_git/commit.rb', line 142 def at(time) self.time = self.commit_time = time return self end |
#by(handle) ⇒ Object
DSL method to set author and committer in one step
137 138 139 140 |
# File 'lib/multi_git/commit.rb', line 137 def by(handle) self. = self.committer = handle return self end |
#tree { ... } ⇒ Tree::Builder
92 93 94 95 |
# File 'lib/multi_git/commit.rb', line 92 def tree(&block) @tree.instance_eval(&block) if block @tree end |