Class: Bringit::Tree
- Inherits:
-
Object
- Object
- Bringit::Tree
- Includes:
- EncodingHelper
- Defined in:
- lib/bringit/tree.rb
Constant Summary
Constants included from EncodingHelper
EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD
Instance Attribute Summary collapse
-
#commit_id ⇒ Object
Returns the value of attribute commit_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#root_id ⇒ Object
Returns the value of attribute root_id.
-
#submodule_url ⇒ Object
Returns the value of attribute submodule_url.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.find_id_by_path(repository, root_id, path) ⇒ Object
Recursive search of tree id for path.
-
.where(repository, sha, path = nil) ⇒ Object
Get list of tree objects for repository based on commit sha and path Uses rugged for raw objects.
Instance Method Summary collapse
- #contributing? ⇒ Boolean
- #dir? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(options) ⇒ Tree
constructor
A new instance of Tree.
- #readme? ⇒ Boolean
- #submodule? ⇒ Boolean
Methods included from EncodingHelper
Constructor Details
#initialize(options) ⇒ Tree
Returns a new instance of Tree.
74 75 76 77 78 |
# File 'lib/bringit/tree.rb', line 74 def initialize() %w(id root_id name path type mode commit_id).each do |key| self.send("#{key}=", [key.to_sym]) end end |
Instance Attribute Details
#commit_id ⇒ Object
Returns the value of attribute commit_id.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def commit_id @commit_id end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def id @id end |
#mode ⇒ Object
Returns the value of attribute mode.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def path @path end |
#root_id ⇒ Object
Returns the value of attribute root_id.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def root_id @root_id end |
#submodule_url ⇒ Object
Returns the value of attribute submodule_url.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def submodule_url @submodule_url end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/bringit/tree.rb', line 5 def type @type end |
Class Method Details
.find_id_by_path(repository, root_id, path) ⇒ Object
Recursive search of tree id for path
Ex.
blog/ # oid: 1a
app/ # oid: 2a
models/ # oid: 3a
views/ # oid: 4a
Tree.find_id_by_path(repo, ‘1a’, ‘app/models’) # => ‘3a’
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bringit/tree.rb', line 54 def find_id_by_path(repository, root_id, path) root_tree = repository.lookup(root_id) path = path.sub(%r{\A/*}, '') path_arr = path.split('/') entry = root_tree.find do |entry| entry[:name] == path_arr[0] && entry[:type] == :tree end return nil unless entry if path_arr.size > 1 path_arr.shift find_id_by_path(repository, entry[:oid], path_arr.join('/')) else entry[:oid] end end |
.where(repository, sha, path = nil) ⇒ Object
Get list of tree objects for repository based on commit sha and path Uses rugged for raw objects
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bringit/tree.rb', line 12 def where(repository, sha, path = nil) path = path&.sub(%r{\A/*}, '') path = nil if path == '' || path == '/' commit = repository.lookup(sha) root_tree = commit.tree tree = if path id = find_id_by_path(repository, root_tree.oid, path) if id repository.lookup(id) else [] end else root_tree end tree.map do |entry| new( id: entry[:oid], root_id: root_tree.oid, name: entry[:name], type: entry[:type], mode: entry[:filemode], path: path ? File.join(path, entry[:name]) : entry[:name], commit_id: sha, ) end end |
Instance Method Details
#contributing? ⇒ Boolean
100 101 102 |
# File 'lib/bringit/tree.rb', line 100 def contributing? name =~ /^contributing/i end |
#dir? ⇒ Boolean
84 85 86 |
# File 'lib/bringit/tree.rb', line 84 def dir? type == :tree end |
#file? ⇒ Boolean
88 89 90 |
# File 'lib/bringit/tree.rb', line 88 def file? type == :blob end |
#readme? ⇒ Boolean
96 97 98 |
# File 'lib/bringit/tree.rb', line 96 def readme? name =~ /^readme/i end |
#submodule? ⇒ Boolean
92 93 94 |
# File 'lib/bringit/tree.rb', line 92 def submodule? type == :commit end |