Class: Bananajour::Repository
- Inherits:
-
Object
- Object
- Bananajour::Repository
- Defined in:
- lib/bananajour/repository.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dirname ⇒ Object
- #exist? ⇒ Boolean
- #grit_repo ⇒ Object
- #html_id ⇒ Object
- #init! ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #name ⇒ Object
- #readme_file ⇒ Object
- #recent_commits ⇒ Object
- #remove! ⇒ Object
- #rendered_readme ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
- #web_uri ⇒ Object
Constructor Details
#initialize(path) ⇒ Repository
Returns a new instance of Repository.
12 13 14 |
# File 'lib/bananajour/repository.rb', line 12 def initialize(path) @path = Pathname(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/bananajour/repository.rb', line 18 def path @path end |
Class Method Details
.for_name(name) ⇒ Object
6 7 8 |
# File 'lib/bananajour/repository.rb', line 6 def self.for_name(name) new(Bananajour.repositories_path.join(name + ".git")) end |
.html_id(name) ⇒ Object
9 10 11 |
# File 'lib/bananajour/repository.rb', line 9 def self.html_id(name) name.gsub(/[^A-Za-z-]+/, '').downcase end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 |
# File 'lib/bananajour/repository.rb', line 15 def ==(other) other.respond_to?(:path) && self.path == other.path end |
#dirname ⇒ Object
32 33 34 |
# File 'lib/bananajour/repository.rb', line 32 def dirname path.split.last.to_s end |
#exist? ⇒ Boolean
19 20 21 |
# File 'lib/bananajour/repository.rb', line 19 def exist? path.exist? end |
#grit_repo ⇒ Object
44 45 46 |
# File 'lib/bananajour/repository.rb', line 44 def grit_repo @grit_repo ||= Grit::Repo.new(path) end |
#html_id ⇒ Object
29 30 31 |
# File 'lib/bananajour/repository.rb', line 29 def html_id self.class.html_id(name) end |
#init! ⇒ Object
22 23 24 25 |
# File 'lib/bananajour/repository.rb', line 22 def init! path.mkpath Dir.chdir(path) { `git init --bare` } end |
#name ⇒ Object
26 27 28 |
# File 'lib/bananajour/repository.rb', line 26 def name dirname.sub(".git",'') end |
#readme_file ⇒ Object
50 51 52 |
# File 'lib/bananajour/repository.rb', line 50 def readme_file grit_repo.tree.contents.find {|c| c.name =~ /readme/i} end |
#recent_commits ⇒ Object
47 48 49 |
# File 'lib/bananajour/repository.rb', line 47 def recent_commits @commits ||= grit_repo.commits(nil, 10) end |
#remove! ⇒ Object
65 66 67 |
# File 'lib/bananajour/repository.rb', line 65 def remove! path.rmtree end |
#rendered_readme ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bananajour/repository.rb', line 53 def rendered_readme case File.extname(readme_file.name) when /\.md/i, /\.markdown/i require 'rdiscount' RDiscount.new(readme_file.data).to_html when /\.textile/i require 'redcloth' RedCloth.new(readme_file.data).to_html(:textile) end rescue LoadError "" end |
#to_hash ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bananajour/repository.rb', line 68 def to_hash heads = grit_repo.heads { "name" => name, "html_friendly_name" => html_id, # TODO: Deprecate in v3. Renamed to html_id since 2.1.4 "html_id" => html_id, "uri" => uri, "heads" => heads.map {|h| h.name}, "recent_commits" => recent_commits.collect do |c| c.to_hash.merge( "head" => (head = heads.find {|h| h.commit == c}) && head.name, "gravatar" => c..gravatar_uri ) end, "bananajour" => Bananajour.to_hash } end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/bananajour/repository.rb', line 35 def to_s name end |
#uri ⇒ Object
38 39 40 |
# File 'lib/bananajour/repository.rb', line 38 def uri Bananajour.git_uri + dirname end |
#web_uri ⇒ Object
41 42 43 |
# File 'lib/bananajour/repository.rb', line 41 def web_uri Bananajour.web_uri + "#" + html_id end |