Class: Githug::Repository
- Inherits:
-
Object
- Object
- Githug::Repository
- Defined in:
- lib/githug/repository.rb
Instance Attribute Summary collapse
-
#grit ⇒ Object
Returns the value of attribute grit.
Instance Method Summary collapse
- #create_gitignore ⇒ Object
-
#init(location = ".") ⇒ Object
Initialize a Git repo.
-
#initialize(location = ".") ⇒ Repository
constructor
A new instance of Repository.
- #method_missing(method, *args, &block) ⇒ Object
- #reset ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(location = ".") ⇒ Repository
Returns a new instance of Repository.
7 8 9 10 11 |
# File 'lib/githug/repository.rb', line 7 def initialize(location = ".") @grit = Grit::Repo.new(location) rescue Grit::InvalidGitRepositoryError @grit = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/githug/repository.rb', line 40 def method_missing(method, *args, &block) if @grit && @grit.respond_to?(method) return @grit.send(method, *args, &block) end super end |
Instance Attribute Details
#grit ⇒ Object
Returns the value of attribute grit.
5 6 7 |
# File 'lib/githug/repository.rb', line 5 def grit @grit end |
Instance Method Details
#create_gitignore ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/githug/repository.rb', line 23 def create_gitignore Dir.chdir("git_hug") if File.exists?("./git_hug") File.open(".gitignore", "w") do |file| file.puts(".profile.yml") file.puts(".gitignore") end end |
#init(location = ".") ⇒ Object
Initialize a Git repo. If the repo already exists, do nothing.
36 37 38 |
# File 'lib/githug/repository.rb', line 36 def init(location = ".") @grit = Grit::Repo.init(location) end |
#reset ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/githug/repository.rb', line 13 def reset dont_delete = ["..", ".", ".profile.yml"] if File.basename(Dir.pwd) == "git_hug" Dir.entries(Dir.pwd).each do |file| FileUtils.rm_rf(file) unless dont_delete.include?(file) end end create_gitignore end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/githug/repository.rb', line 31 def valid? !@grit.nil? end |