Class: Githug::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/githug/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#gritObject

Returns the value of attribute grit.



5
6
7
# File 'lib/githug/repository.rb', line 5

def grit
  @grit
end

Instance Method Details

#create_gitignoreObject



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

#resetObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/githug/repository.rb', line 31

def valid?
  !@grit.nil?
end