Class: GitGoggles::Repository
- Inherits:
-
Object
- Object
- GitGoggles::Repository
- Defined in:
- lib/git_goggles/repository.rb
Instance Method Summary collapse
- #_path ⇒ Object
- #_repo ⇒ Object
- #branch(branch_name) ⇒ Object
- #branches ⇒ Object
- #commit(sha) ⇒ Object
- #commits ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(name) ⇒ Repository
constructor
A new instance of Repository.
- #tag(tag_name) ⇒ Object
- #tags ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(name) ⇒ Repository
Returns a new instance of Repository.
3 4 5 |
# File 'lib/git_goggles/repository.rb', line 3 def initialize(name) @name = name end |
Instance Method Details
#_path ⇒ Object
69 70 71 |
# File 'lib/git_goggles/repository.rb', line 69 def _path File.join(GitGoggles.root_dir, @name) end |
#_repo ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/git_goggles/repository.rb', line 73 def _repo if exists? @repo ||= Grit::Repo.new(_path, :is_bare => true) else nil end end |
#branch(branch_name) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/git_goggles/repository.rb', line 11 def branch(branch_name) if branch = _repo.branches.find { |branch| branch.name == branch_name } { :name => branch.name.force_encoding("ISO-8859-1").encode("UTF-8"), :latest_commit => branch.commit.sha.force_encoding("ISO-8859-1").encode("UTF-8") } end end |
#branches ⇒ Object
7 8 9 |
# File 'lib/git_goggles/repository.rb', line 7 def branches _repo.branches.map(&:name) end |
#commit(sha) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/git_goggles/repository.rb', line 34 def commit(sha) if commit = _repo.commit(sha) { :author => "#{commit..name.force_encoding("ISO-8859-1").encode("UTF-8")} <#{commit..email.force_encoding("ISO-8859-1").encode("UTF-8")}>", :message => commit..force_encoding("ISO-8859-1").encode("UTF-8"), :date => commit.date.to_s.force_encoding("ISO-8859-1").encode("UTF-8"), :diffs => commit.diffs.map { |diff| diff.diff.force_encoding("ISO-8859-1").encode("UTF-8") } } end end |
#commits ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/git_goggles/repository.rb', line 20 def commits output = [] _repo.commits('master', 100).each do |commit| output << { :author => "#{commit..name.force_encoding("ISO-8859-1").encode("UTF-8")} <#{commit..email.force_encoding("ISO-8859-1").encode("UTF-8")}>", :message => commit..force_encoding("ISO-8859-1").encode("UTF-8"), :sha => commit.id.force_encoding("ISO-8859-1").encode("UTF-8") } end output end |
#exists? ⇒ Boolean
45 46 47 |
# File 'lib/git_goggles/repository.rb', line 45 def exists? File.exists?(_path) end |
#tag(tag_name) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/git_goggles/repository.rb', line 53 def tag(tag_name) if tag = _repo..find { |tag| tag.name == tag_name } { :name => tag.name.force_encoding("ISO-8859-1").encode("UTF-8"), :commit => tag.commit.sha.force_encoding("ISO-8859-1").encode("UTF-8") } end end |
#tags ⇒ Object
49 50 51 |
# File 'lib/git_goggles/repository.rb', line 49 def _repo..map(&:name) end |
#to_json ⇒ Object
62 63 64 65 66 67 |
# File 'lib/git_goggles/repository.rb', line 62 def to_json { :name => @name, :branches => _repo.branches.map(&:name) }.to_json end |