Class: VCSToolkit::Objects::Tree
- Defined in:
- lib/vcs_toolkit/objects/tree.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#trees ⇒ Object
readonly
Returns the value of attribute trees.
Attributes inherited from Object
Instance Method Summary collapse
-
#all_files(object_store, ignore: []) ⇒ Object
Iterates over all [file, blob_id] pairs recursively (including files in child trees).
-
#find(object_store, path) ⇒ Object
Finds the object id of a blob or tree by its relative path to the current tree.
-
#initialize(files:, trees:, id: nil, **context) ⇒ Tree
constructor
A new instance of Tree.
Methods inherited from Object
Methods included from Serializable
Methods included from Utils::HashableObject
Constructor Details
#initialize(files:, trees:, id: nil, **context) ⇒ Tree
Returns a new instance of Tree.
14 15 16 17 18 19 20 21 |
# File 'lib/vcs_toolkit/objects/tree.rb', line 14 def initialize(files:, trees:, id: nil, **context) @files = files @trees = trees super id: id, object_type: :tree, **context end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
11 12 13 |
# File 'lib/vcs_toolkit/objects/tree.rb', line 11 def files @files end |
#trees ⇒ Object (readonly)
Returns the value of attribute trees.
11 12 13 |
# File 'lib/vcs_toolkit/objects/tree.rb', line 11 def trees @trees end |
Instance Method Details
#all_files(object_store, ignore: []) ⇒ Object
Iterates over all [file, blob_id] pairs recursively (including files in child trees).
27 28 29 |
# File 'lib/vcs_toolkit/objects/tree.rb', line 27 def all_files(object_store, ignore: []) enum_for :yield_all_files, object_store, ignore: ignore end |
#find(object_store, path) ⇒ Object
Finds the object id of a blob or tree by its relative path to the current tree.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vcs_toolkit/objects/tree.rb', line 35 def find(object_store, path) if [nil, '', '/', '.'].include? path id elsif files.key? path files[path] else dir_name, sub_path = path.split('/', 2) return nil unless trees.key? dir_name subtree = object_store.fetch trees[dir_name] subtree.find(object_store, sub_path) end end |