Class: Git::Lighttp::ProjectHandler
Overview
:nodoc:
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Path to git comamnd.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#repository ⇒ Object
Returns the value of attribute repository.
Instance Method Summary collapse
- #cli(command, *args) ⇒ Object
- #info_packs_path ⇒ Object
-
#initialize(project_root, path = '/usr/bin/git') ⇒ ProjectHandler
constructor
A new instance of ProjectHandler.
- #loose_object_path(*hash) ⇒ Object
- #pack_idx_path(pack) ⇒ Object
- #path_to(*args) ⇒ Object
- #read_file(*file) ⇒ Object
- #run(command, *args) ⇒ Object
- #tree(ref = 'HEAD', path = '') ⇒ Object
Constructor Details
#initialize(project_root, path = '/usr/bin/git') ⇒ ProjectHandler
Returns a new instance of ProjectHandler.
72 73 74 75 76 |
# File 'lib/git/lighttp.rb', line 72 def initialize(project_root, path = '/usr/bin/git') @repository = nil @path = check_path(File.(path)) @project_root = check_path(File.(project_root)) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Path to git comamnd
66 67 68 |
# File 'lib/git/lighttp.rb', line 66 def path @path end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
68 69 70 |
# File 'lib/git/lighttp.rb', line 68 def project_root @project_root end |
#repository ⇒ Object
Returns the value of attribute repository.
70 71 72 |
# File 'lib/git/lighttp.rb', line 70 def repository @repository end |
Instance Method Details
#cli(command, *args) ⇒ Object
86 87 88 |
# File 'lib/git/lighttp.rb', line 86 def cli(command, *args) "#{@path} #{args.unshift(command.to_s.tr('_', '-')).compact.join(' ')}" end |
#info_packs_path ⇒ Object
106 107 108 |
# File 'lib/git/lighttp.rb', line 106 def info_packs_path path_to(:objects, :info, :packs) end |
#loose_object_path(*hash) ⇒ Object
98 99 100 |
# File 'lib/git/lighttp.rb', line 98 def loose_object_path(*hash) path_to(:objects, *hash) end |
#pack_idx_path(pack) ⇒ Object
102 103 104 |
# File 'lib/git/lighttp.rb', line 102 def pack_idx_path(pack) path_to(:objects, :pack, pack) end |
#path_to(*args) ⇒ Object
78 79 80 |
# File 'lib/git/lighttp.rb', line 78 def path_to(*args) File.join(@repository || @project_root, *args.compact.map(&:to_s)) end |
#read_file(*file) ⇒ Object
94 95 96 |
# File 'lib/git/lighttp.rb', line 94 def read_file(*file) File.read(path_to(*file)) end |
#run(command, *args) ⇒ Object
90 91 92 |
# File 'lib/git/lighttp.rb', line 90 def run(command, *args) chdir { %x(#{cli command, *args}) } end |
#tree(ref = 'HEAD', path = '') ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/git/lighttp.rb', line 110 def tree(ref = 'HEAD', path = '') list = run("ls-tree --abbrev=6 --full-tree --long #{ref}:#{path}") if list tree = [] pattern = /^ (?<ty>\d{3}) (?<pu>\d) (?<pg>\d) (?<po>\d)[ ] (?<ot>\w.*?)[ ] (?<oh>.{6})[ \t]{0,} (?<sz>.*?)\t (?<nm>.*?)\n /mux list.scan pattern do |ty, pu, pg, po, ot, oh, sz, nm| object = { ftype: ftype[ty], fperm: "#{fperm[pu.to_i]}#{fperm[pg.to_i]}#{fperm[po.to_i]}", otype: ot.to_sym, ohash: oh, fsize: fsize(sz, 2), fname: nm } object[:objects] = nil if object[:otype] == :tree tree << object end tree else false end end |