Class: Todidnt::GitCommand

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

Instance Method Summary collapse

Constructor Details

#initialize(command, options) ⇒ GitCommand

Returns a new instance of GitCommand.



5
6
7
8
9
10
# File 'lib/todidnt/git_command.rb', line 5

def initialize(command, options)
  @command = command
  @options = options

  @process = Subprocess::Process.new(command_with_options, :stdout => Subprocess::PIPE)
end

Instance Method Details

#command_with_optionsObject



18
19
20
21
22
23
24
25
26
# File 'lib/todidnt/git_command.rb', line 18

def command_with_options
  full_command = @command.to_s

  for option in @options
    full_command << " #{option.join(' ')}"
  end

  "git #{full_command}"
end

#execute!(&blk) ⇒ Object



12
13
14
15
16
# File 'lib/todidnt/git_command.rb', line 12

def execute!(&blk)
  @process.stdout.each_line do |line|
    yield line.chomp
  end
end