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.
76 77 78 79 80 |
# File 'lib/git/lighttp.rb', line 76 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
70 71 72 |
# File 'lib/git/lighttp.rb', line 70 def path @path end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
72 73 74 |
# File 'lib/git/lighttp.rb', line 72 def project_root @project_root end |
#repository ⇒ Object
Returns the value of attribute repository.
74 75 76 |
# File 'lib/git/lighttp.rb', line 74 def repository @repository end |
Instance Method Details
#cli(command, *args) ⇒ Object
90 91 92 |
# File 'lib/git/lighttp.rb', line 90 def cli(command, *args) %Q[#{@path} #{args.unshift(command.to_s.gsub("_","-")).compact.join(" ")}] end |
#info_packs_path ⇒ Object
110 111 112 |
# File 'lib/git/lighttp.rb', line 110 def info_packs_path path_to(:objects, :info, :packs) end |
#loose_object_path(*hash) ⇒ Object
102 103 104 |
# File 'lib/git/lighttp.rb', line 102 def loose_object_path(*hash) path_to(:objects, *hash) end |
#pack_idx_path(pack) ⇒ Object
106 107 108 |
# File 'lib/git/lighttp.rb', line 106 def pack_idx_path(pack) path_to(:objects, :pack, pack) end |
#path_to(*args) ⇒ Object
82 83 84 |
# File 'lib/git/lighttp.rb', line 82 def path_to(*args) File.join(@repository || @project_root, *(args.compact.map(&:to_s))) end |
#read_file(*file) ⇒ Object
98 99 100 |
# File 'lib/git/lighttp.rb', line 98 def read_file(*file) File.read(path_to(*file)) end |
#run(command, *args) ⇒ Object
94 95 96 |
# File 'lib/git/lighttp.rb', line 94 def run(command, *args) chdir{ %x[#{cli command, *args}] } end |
#tree(ref = "HEAD", path = "") ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/git/lighttp.rb', line 114 def tree(ref = "HEAD", path = "") list = run("ls-tree --abbrev=6 --full-tree --long #{ref}:#{path}") if list tree = [] list.scan %r{^(\d{3})(\d)(\d)(\d) (\w.*?) (.{6})[ \t]{0,}(.*?)\t(.*?)\n}m do object = { :ftype => ftype[$1], :fperm => "#{fperm[$2.to_i]}#{fperm[$3.to_i]}#{fperm[$4.to_i]}", :otype => $5.to_sym, :ohash => $6, :fsize => fsize($7, 2), :fname => $8 } object[:objects] = nil if object[:otype] == :tree tree << object end tree else nil end end |