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.



6
7
8
9
10
# File 'lib/githug/repository.rb', line 6

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



39
40
41
42
43
44
# File 'lib/githug/repository.rb', line 39

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.



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

def grit
  @grit
end

Instance Method Details

#create_gitignoreObject



22
23
24
25
26
27
28
# File 'lib/githug/repository.rb', line 22

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.



35
36
37
# File 'lib/githug/repository.rb', line 35

def init(location = ".")
  @grit = Grit::Repo.init(location)
end

#resetObject



12
13
14
15
16
17
18
19
20
# File 'lib/githug/repository.rb', line 12

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)


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

def valid?
  !@grit.nil?
end