Class: Ginatra::Repo
- Inherits:
-
Object
- Object
- Ginatra::Repo
- Defined in:
- lib/ginatra/repo.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
Instance Method Summary collapse
-
#branch_exists?(branch_name) ⇒ Boolean
Checks existence of branch by name.
-
#branches ⇒ Object
Returns list of branches sorted by name alphabetically.
-
#branches_with(commit) ⇒ Object
Returns list of branches containing the commit.
-
#commit(sha) ⇒ Rugged::Commit
Return a commit corresponding to sha in the repo.
-
#commit_by_tag(name) ⇒ Object
Return a commit corresponding to tag in the repo.
-
#commits(branch = 'master', max_count = 10, skip = 0) ⇒ Array<Rugged::Commit>
Return a list of commits in a certain branch, including pagination options and all the refs.
-
#find_blob(oid) ⇒ Object
Find blob by oid.
-
#find_tree(oid) ⇒ Object
Find tree by tree oid or branch name.
-
#initialize(path) ⇒ Ginatra::Repo
constructor
Create a new repository, and sort out clever stuff including assigning the param, the name and the description.
-
#method_missing(sym, *args, &block) ⇒ Object
Catch all.
-
#respond_to?(sym) ⇒ Boolean
to correspond to the #method_missing definition.
-
#to_rugged ⇒ Object
Returns Rugged::Repository instance.
Constructor Details
#initialize(path) ⇒ Ginatra::Repo
Create a new repository, and sort out clever stuff including assigning the param, the name and the description.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ginatra/repo.rb', line 12 def initialize(path) @repo = Rugged::Repository.new(path) @param = File.split(path).last @name = @param @description = '' if File.exists?("#{@repo.path}description") @description = File.read("#{@repo.path}description").strip @description = '' if @description.match(/\AUnnamed repository;/) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
update respond_to? method
Catch all
105 106 107 108 109 110 111 |
# File 'lib/ginatra/repo.rb', line 105 def method_missing(sym, *args, &block) if @repo.respond_to?(sym) @repo.send(sym, *args, &block) else super end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/ginatra/repo.rb', line 5 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ginatra/repo.rb', line 5 def name @name end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
5 6 7 |
# File 'lib/ginatra/repo.rb', line 5 def param @param end |
Instance Method Details
#branch_exists?(branch_name) ⇒ Boolean
Checks existence of branch by name
78 79 80 |
# File 'lib/ginatra/repo.rb', line 78 def branch_exists?(branch_name) @repo.branches.exists?(branch_name) end |
#branches ⇒ Object
Returns list of branches sorted by name alphabetically
61 62 63 |
# File 'lib/ginatra/repo.rb', line 61 def branches @repo.branches.each(:local).sort_by {|b| b.name } end |
#branches_with(commit) ⇒ Object
Returns list of branches containing the commit
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ginatra/repo.rb', line 66 def branches_with(commit) b = [] branches.each do |branch| walker = Rugged::Walker.new(@repo) walker.sorting(Rugged::SORT_TOPO) walker.push(@repo.ref("refs/heads/#{branch.name}").target) walker.collect { |c| b << branch if c.oid == commit } end b end |
#commit(sha) ⇒ Rugged::Commit
Return a commit corresponding to sha in the repo.
27 28 29 |
# File 'lib/ginatra/repo.rb', line 27 def commit(sha) @repo.lookup(sha) end |
#commit_by_tag(name) ⇒ Object
Return a commit corresponding to tag in the repo.
32 33 34 35 36 37 38 39 40 |
# File 'lib/ginatra/repo.rb', line 32 def commit_by_tag(name) target = @repo.ref("refs/tags/#{name}").target if target.is_a? Rugged::Tag::Annotation target = target.target end target end |
#commits(branch = 'master', max_count = 10, skip = 0) ⇒ Array<Rugged::Commit>
Return a list of commits in a certain branch, including pagination options and all the refs.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ginatra/repo.rb', line 49 def commits(branch='master', max_count=10, skip=0) raise Ginatra::InvalidRef unless branch_exists?(branch) walker = Rugged::Walker.new(@repo) walker.sorting(Rugged::SORT_TOPO) walker.push(@repo.ref("refs/heads/#{branch}").target) commits = walker.collect {|commit| commit } commits[skip, max_count] end |
#find_blob(oid) ⇒ Object
Find blob by oid
83 84 85 |
# File 'lib/ginatra/repo.rb', line 83 def find_blob(oid) Rugged::Blob.new @repo, oid end |
#find_tree(oid) ⇒ Object
Find tree by tree oid or branch name
88 89 90 91 92 93 94 95 |
# File 'lib/ginatra/repo.rb', line 88 def find_tree(oid) if branch_exists?(oid) last_commit_sha = @repo.ref("refs/heads/#{oid}").target.oid lookup(last_commit_sha).tree else lookup(oid) end end |
#respond_to?(sym) ⇒ Boolean
to correspond to the #method_missing definition
114 115 116 |
# File 'lib/ginatra/repo.rb', line 114 def respond_to?(sym) @repo.respond_to?(sym) || super end |
#to_rugged ⇒ Object
Returns Rugged::Repository instance
98 99 100 |
# File 'lib/ginatra/repo.rb', line 98 def to_rugged @repo end |