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
- #exists? ⇒ Boolean
- #grit_repo ⇒ Object
- #html_friendly_name ⇒ 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.
11 12 13 |
# File 'lib/bananajour/repository.rb', line 11 def initialize(path) @path = Fancypath(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/bananajour/repository.rb', line 17 def path @path end |
Class Method Details
.for_name(name) ⇒ Object
5 6 7 |
# File 'lib/bananajour/repository.rb', line 5 def self.for_name(name) new(Bananajour.repositories_path.join(name + ".git")) end |
.html_friendly_name(name) ⇒ Object
8 9 10 |
# File 'lib/bananajour/repository.rb', line 8 def self.html_friendly_name(name) name.gsub(/[^A-Za-z-]+/, '').downcase end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/bananajour/repository.rb', line 14 def ==(other) other.respond_to?(:path) && self.path == other.path end |
#dirname ⇒ Object
31 32 33 |
# File 'lib/bananajour/repository.rb', line 31 def dirname path.split.last.to_s end |
#exists? ⇒ Boolean
18 19 20 |
# File 'lib/bananajour/repository.rb', line 18 def exists? path.exists? end |
#grit_repo ⇒ Object
43 44 45 |
# File 'lib/bananajour/repository.rb', line 43 def grit_repo @grit_repo ||= Grit::Repo.new(path) end |
#html_friendly_name ⇒ Object
28 29 30 |
# File 'lib/bananajour/repository.rb', line 28 def html_friendly_name self.class.html_friendly_name(name) end |
#init! ⇒ Object
21 22 23 24 |
# File 'lib/bananajour/repository.rb', line 21 def init! path.create_dir Dir.chdir(path) { `git init --bare` } end |
#name ⇒ Object
25 26 27 |
# File 'lib/bananajour/repository.rb', line 25 def name dirname.sub(".git",'') end |
#readme_file ⇒ Object
49 50 51 |
# File 'lib/bananajour/repository.rb', line 49 def readme_file grit_repo.tree.contents.find {|c| c.name =~ /readme/i} end |
#recent_commits ⇒ Object
46 47 48 |
# File 'lib/bananajour/repository.rb', line 46 def recent_commits @commits ||= grit_repo.commits(nil, 10) end |
#remove! ⇒ Object
64 65 66 |
# File 'lib/bananajour/repository.rb', line 64 def remove! path.rmtree end |
#rendered_readme ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bananajour/repository.rb', line 52 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bananajour/repository.rb', line 67 def to_hash heads = grit_repo.heads { "name" => name, "html_friendly_name" => html_friendly_name, "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
34 35 36 |
# File 'lib/bananajour/repository.rb', line 34 def to_s name end |
#uri ⇒ Object
37 38 39 |
# File 'lib/bananajour/repository.rb', line 37 def uri Bananajour.git_uri + dirname end |
#web_uri ⇒ Object
40 41 42 |
# File 'lib/bananajour/repository.rb', line 40 def web_uri Bananajour.web_uri + "#" + html_friendly_name end |