Class: GitChain::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
8
# File 'lib/git_chain/runner.rb', line 4

def initialize(path:)
  @git = GitHelper.new(path, Git.open(path))
  @storage = GitChain::Storage.new(path: path)
  @chain = GitChain::Chain.new(storage, git)
end

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



3
4
5
# File 'lib/git_chain/runner.rb', line 3

def chain
  @chain
end

#gitObject (readonly)

Returns the value of attribute git.



3
4
5
# File 'lib/git_chain/runner.rb', line 3

def git
  @git
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/git_chain/runner.rb', line 3

def storage
  @storage
end

Instance Method Details

#add(parent:, old_base: nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/git_chain/runner.rb', line 37

def add(parent:, old_base: nil)
  chain.mark_branch_as_dependent(
    child: git.current_branch,
    parent: parent,
    old_base: old_base
  )
end

#call(command, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/git_chain/runner.rb', line 10

def call(command, *args)
  case command
  when 'show'
    show(branch: args[0])
  when 'list'
    list()
  when 'add'
    add(parent: args[0], old_base: args[1])
  when 'rebase'
    rebase(sub_command: args.first)
  else
    raise "Unknown Command: #{command}"
  end
end

#listObject



33
34
35
# File 'lib/git_chain/runner.rb', line 33

def list
  storage.print
end

#rebase(sub_command: nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/git_chain/runner.rb', line 45

def rebase(sub_command: nil)
  if sub_command == 'all'
    chain.rebase_all(git.current_branch)
  else
    chain.rebase(git.current_branch)
  end
end

#show(branch: nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/git_chain/runner.rb', line 25

def show(branch: nil)
  if branch
    storage.print_branch(branch: branch)
  else
    storage.print_branch(branch: git.current_branch)
  end
end