Class: Speedflow::Plugin::Git::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/speedflow/plugin/git/client.rb

Overview

Git client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, prompt) ⇒ Client

Initialize.

config - Speedflow::Plugin::Git::Configuration instance. prompt - Speedflow::Plugin::Git::Prompt instance.

Examples

Client.new({}, Speedflow::Plugin::Git::Prompt.new)
# => <Speedflow::Plugin::Git::Client>

Returns nothing.



25
26
27
28
# File 'lib/speedflow/plugin/git/client.rb', line 25

def initialize(config, prompt)
  @config = config
  @prompt = prompt
end

Instance Attribute Details

#git_clientObject

Public: Git client.

Returns ::Git instance.



69
70
71
# File 'lib/speedflow/plugin/git/client.rb', line 69

def git_client
  @git_client ||= ::Git
end

#promptObject

Public: Prompt.

Returns ::Speedflow::Plugin::Git::Prompt instance.



76
77
78
# File 'lib/speedflow/plugin/git/client.rb', line 76

def prompt
  @prompt ||= ::Speedflow::Plugin::Git::Prompt.new
end

Instance Method Details

#branches(branch_type = :local) ⇒ Object

Public: Branches.

branch_type - String of type (:local or :remote)

Returns Array of local branches.



49
50
51
52
53
54
# File 'lib/speedflow/plugin/git/client.rb', line 49

def branches(branch_type = :local)
  safe do
    git = git_client.open('.')
    git.branches.send(branch_type)
  end
end

#create_branch(branch, branch_from) ⇒ Object

Public: Create branch.

branch - Branch. branch_from - Branch from.

Returns Git::Branch.



36
37
38
39
40
41
42
# File 'lib/speedflow/plugin/git/client.rb', line 36

def create_branch(branch, branch_from)
  safe do
    git = git_client.open('.')
    git.branch(branch_from).checkout unless branch_from.empty?
    git.branch(branch).checkout
  end
end

#safeObject

Public: Safe process Git action.

Returns nothing.



59
60
61
62
63
64
# File 'lib/speedflow/plugin/git/client.rb', line 59

def safe
  yield
rescue StandardError => exception
  prompt.errors exception
  abort
end