Class: Ginatra::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/ginatra/repo.rb

Overview

Convenience class for me!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repo

Returns a new instance of Repo.



14
15
16
17
18
19
20
21
# File 'lib/ginatra/repo.rb', line 14

def initialize(path)
  @repo = Grit::Repo.new(path)
  @param = File.split(path).last
  @name = @param
  @description = @repo.description
  @description = "Please edit the #{@repo.path}/description file for this repository and set the description for it." if /^Unnamed repository;/.match(@description)
  @repo
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



45
46
47
# File 'lib/ginatra/repo.rb', line 45

def method_missing(sym, *args, &block)
  @repo.send(sym, *args, &block)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/ginatra/repo.rb', line 12

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/ginatra/repo.rb', line 12

def name
  @name
end

#paramObject (readonly)

Returns the value of attribute param.



12
13
14
# File 'lib/ginatra/repo.rb', line 12

def param
  @param
end

Instance Method Details

#add_refs(commit) ⇒ Object

TODO: Perhaps move into commit class.



38
39
40
41
42
43
# File 'lib/ginatra/repo.rb', line 38

def add_refs(commit)
  commit.refs = []
  refs = @repo.refs.select { |ref| ref.commit.id == commit.id }
  commit.refs << refs
  commit.refs.flatten!
end

#commit(id) ⇒ Object



23
24
25
26
27
28
# File 'lib/ginatra/repo.rb', line 23

def commit(id)
  @commit = @repo.commit(id)
  raise(Ginatra::InvalidCommit.new(id)) if @commit.nil?
  add_refs(@commit)
  @commit
end

#commits(start = 'master', max_count = 10, skip = 0) ⇒ Object

Raises:



30
31
32
33
34
35
# File 'lib/ginatra/repo.rb', line 30

def commits(start = 'master', max_count = 10, skip = 0)
  raise(Ginatra::Error.new("max_count cannot be less than 0")) if max_count < 0
  @repo.commits(start, max_count, skip).each do |commit|
    add_refs(commit) 
  end
end