Class: GitDump::Tree::Builder
- Inherits:
-
PathObject
- Object
- PathObject
- GitDump::Tree::Builder
- Includes:
- Base
- Defined in:
- lib/git_dump/tree/builder.rb
Overview
Creating tree
Instance Attribute Summary
Attributes inherited from PathObject
Instance Method Summary collapse
-
#initialize(repo, dir, name) ⇒ Builder
constructor
A new instance of Builder.
- #inspect ⇒ Object
- #sha ⇒ Object
-
#store(path, content, mode = 0644) ⇒ Object
(also: #[]=)
Store data
contentwith modemodeatpathPassnilas content to remove. -
#store_from(path, from, mode = nil) ⇒ Object
Store data from
fromwith modemode(by default file mode) atpath.
Methods included from Base
Constructor Details
#initialize(repo, dir, name) ⇒ Builder
Returns a new instance of Builder.
10 11 12 13 |
# File 'lib/git_dump/tree/builder.rb', line 10 def initialize(repo, dir, name) super(repo, dir, name) @entries = {} end |
Instance Method Details
#inspect ⇒ Object
39 40 41 |
# File 'lib/git_dump/tree/builder.rb', line 39 def inspect "#<#{self.class} #{@entries.inspect}>" end |
#sha ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git_dump/tree/builder.rb', line 28 def sha repo.treeify(@entries.map do |name, entry| attributes = {:name => name, :sha => entry.sha} if entry.is_a?(self.class) attributes.merge(:type => :tree) else attributes.merge(:type => :blob, :mode => entry.mode) end end) end |
#store(path, content, mode = 0644) ⇒ Object Also known as: []=
Store data content with mode mode at path Pass nil as content to remove
17 18 19 |
# File 'lib/git_dump/tree/builder.rb', line 17 def store(path, content, mode = 0644) put_at(parse_path(path), content && repo.data_sha(content), mode) end |
#store_from(path, from, mode = nil) ⇒ Object
Store data from from with mode mode (by default file mode) at path
23 24 25 26 |
# File 'lib/git_dump/tree/builder.rb', line 23 def store_from(path, from, mode = nil) mode ||= File.stat(from).mode put_at(parse_path(path), repo.path_sha(from), mode) end |