Class: Nwiki::Core::GitAccess
- Inherits:
-
Object
- Object
- Nwiki::Core::GitAccess
- Defined in:
- lib/nwiki/core/git_access.rb
Instance Method Summary collapse
- #all_files ⇒ Object
- #author ⇒ Object
- #config ⇒ Object
- #find_file ⇒ Object
-
#initialize(repo_path) ⇒ GitAccess
constructor
A new instance of GitAccess.
- #log ⇒ Object
- #subtitle ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(repo_path) ⇒ GitAccess
Returns a new instance of GitAccess.
37 38 39 |
# File 'lib/nwiki/core/git_access.rb', line 37 def initialize repo_path @repo = Rugged::Repository.new(::File.(repo_path)) end |
Instance Method Details
#all_files ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nwiki/core/git_access.rb', line 73 def all_files walker = Rugged::Walker.new(@repo).tap do |w| w.sorting(Rugged::SORT_DATE) # new -> old w.push(@repo.head.target) end [].tap { |result| walker.walk.each do |commit| parent = commit.parents.first next unless parent diff = parent.diff(commit) diff.deltas.reject(&:deleted?).each do |delta| new_file_object = delta.new_file fullpath = new_file_object[:path].force_encoding('UTF-8') result << Entry.new(fullpath, @repo.lookup(new_file_object[:oid])) end end }.reduce([]) { |acm, e| acm.map(&:path).include?(e.path) ? acm : acm << e }.reject { |e| e.path.start_with?('__nwiki') # TODO HANDLE DELETED ELEMENT } end |
#author ⇒ Object
57 58 59 60 61 |
# File 'lib/nwiki/core/git_access.rb', line 57 def = config.target.tree.get_entry('author') = @repo.lookup([:oid]) .text.chomp.force_encoding('UTF-8') end |
#config ⇒ Object
41 42 43 |
# File 'lib/nwiki/core/git_access.rb', line 41 def config @repo.branches['config'] end |
#find_file ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/nwiki/core/git_access.rb', line 63 def find_file target = @repo.head.target target.tree.walk_blobs do |path, object| fullpath = path + object[:name] if yield(fullpath) return Entry.new(fullpath, @repo.lookup(object[:oid])) end end end |
#log ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/nwiki/core/git_access.rb', line 96 def log walker = Rugged::Walker.new(@repo).tap do |w| w.sorting(Rugged::SORT_DATE) # new -> old w.push(@repo.head.target) end [].tap do |result| walker.walk.each do |commit| commit_time = Time.at(commit.epoch_time) parent = commit.parents.first next unless parent diff = parent.diff(commit) diff.deltas.reject(&:deleted?).each do |delta| new_file_object = delta.new_file path = new_file_object[:path].force_encoding('UTF-8') result << Diff.new(Entry.new(path, @repo.lookup(new_file_object[:oid])), commit_time) end end end end |
#subtitle ⇒ Object
51 52 53 54 55 |
# File 'lib/nwiki/core/git_access.rb', line 51 def subtitle subtitle_entry = config.target.tree.get_entry('subtitle') subtitle_blob = @repo.lookup(subtitle_entry[:oid]) subtitle_blob.text.chomp.force_encoding('UTF-8') end |
#title ⇒ Object
45 46 47 48 49 |
# File 'lib/nwiki/core/git_access.rb', line 45 def title title_entry = config.target.tree.get_entry('title') title_blob = @repo.lookup(title_entry[:oid]) title_blob.text.chomp.force_encoding('UTF-8') end |