Class: V::Adapters::Git::Tree
- Inherits:
-
ObjectType
- Object
- ObjectType
- V::Adapters::Git::Tree
- Includes:
- Enumerable
- Defined in:
- lib/v/adapters/git/object_types/tree.rb
Constant Summary collapse
- LINE_RE =
/^(\d{6}) (blob|tree) ([[:alnum:]]{40})\t(.+)$/
Class Method Summary collapse
Instance Method Summary collapse
- #/(object, path) ⇒ Object
- #[](object, glob) ⇒ Object
- #content(object) ⇒ Object
- #each(object) ⇒ Object
- #path(parent, *basenames) ⇒ Object
Methods inherited from ObjectType
Class Method Details
.with(environment, attrs = {}) ⇒ Object
7 8 9 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 7 def self.with(environment, attrs = {}) Object.new environment, attrs.update(:type => :tree) end |
Instance Method Details
#/(object, path) ⇒ Object
36 37 38 39 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 36 def /(object, path) parts = path.to_s.split '/' parts.inject(object) { |obj, name| obj.content.fetch name } end |
#[](object, glob) ⇒ Object
33 34 35 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 33 def [](object, glob) raise NotImplementedError end |
#content(object) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 12 def content(object) environment, name, parent = object.environment, object.name, object environment.ls_tree(name).split($/). inject({}) do |mem, line| mode, type, name, basename = LINE_RE.match(line).captures # see git help ls-tree # path.gsub! /(\\n|\\t|\\)/, ... child = Object.new environment, :type => type.to_sym, :name => name, :parent => parent, :basename => basename mem.update basename => child end end |
#each(object) ⇒ Object
29 30 31 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 29 def each(object) object.content.values.each { |v| yield v } end |
#path(parent, *basenames) ⇒ Object
41 42 43 |
# File 'lib/v/adapters/git/object_types/tree.rb', line 41 def path(parent, *basenames) parent.path *basenames end |