Class: G4t::Core

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

Instance Method Summary collapse

Constructor Details

#initializeCore

Returns a new instance of Core.



11
12
13
14
15
# File 'lib/g4t.rb', line 11

def initialize
  @opt = Options.new
  @prompt = TTY::Prompt.new
  start
end

Instance Method Details

#git_init?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/g4t.rb', line 25

def git_init?
  unless File.directory?(".git")
    begin
      options = ["Clone a repo", "Initialize a repo", "Close"]
      userSelect = @prompt.select("The .git directory was not found, what do you want to do?", options)
      git_init_verify(userSelect)
    rescue TTY::Reader::InputInterrupt
      abort("\nCloseed")
    end
  end
end

#git_init_verifyObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/g4t.rb', line 37

def git_init_verify
  case @git_init_select
  when "Clone a repo"
    @opt.clone_repo
  when "Initialize a repo"
    @opt.initialize_git
  else
    abort("It is not possible to continue without a .git repository or cloned repository!")
  end
end

#identify_userObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/g4t.rb', line 48

def identify_user
  if(File.exist?(verify_system)) == false
    begin
      email = @prompt.ask("Github email: ")
      uname = @prompt.ask("Github username: ")
      @opt.run_command("git config --global user.email #{email} && git config --global user.name #{uname}")
    rescue TTY::Reader::InputInterrupt
      abort("\nYou closed the application")
    end
  end
end

#show_panelObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/g4t.rb', line 60

def show_panel
  options = [
    "Add remote address",
    "Add files",
    "Commit files",
    "Push files to branch",
    "Show git status",
    "Show git logs",
    "Show the last commit",
    "Remove a file",
    "Show diff",
    "Change branch",
    "Git pull changes",
    "Restore a file",
    "Reset to a commit",
    "Reset to the last commit",
    "Close"
  ]

  begin
    Options.new.git_info
    opt_select = @prompt.select("Select: ", options)
    verify_option(opt_select)
  rescue TTY::Reader::InputInterrupt
    abort("\nYou has closed the application.")
  end
end

#startObject



109
110
111
# File 'lib/g4t.rb', line 109

def start
  loop { show_panel }
end

#verify_option(option) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/g4t.rb', line 88

def verify_option(option)
  switch = {
    "Add remote address" => @opt.method(:remote_adress),
    "Add files" => @opt.method(:add_files),
    "Commit files" => @opt.method(:commit_files),
    "Push files to branch" => @opt.method(:push_branch),
    "Show git status" => @opt.method(:status),
    "Show git logs" => @opt.method(:logs),
    "Show diff" => @opt.method(:diff),
    "Restore a file" => @opt.method(:restore),
    "Reset to a commit" => @opt.method(:reset),
    "Reset to the last commit" => @opt.method(:hard_reset),
    "Change branch" => @opt.method(:change_branch),
    "Remove a file" => @opt.method(:remove_file),
    "Show the last commit" => @opt.method(:show_last_commit),
    "Git pull changes" => @opt.method(:pull_changes)
  }

  return switch[option].call
end

#verify_systemObject



17
18
19
20
21
22
23
# File 'lib/g4t.rb', line 17

def verify_system
  if OS.windows?
     "C:\\Users\\#{Etc.getlogin}\\.gitconfig" 
  else
    "/home/#{Etc.getlogin}/.gitconfig" 
  end
end