class CaptainHoog::Git

Attributes

env[RW]

Public Class Methods

new() click to toggle source
# File lib/captain_hoog/git.rb, line 6
def initialize
  @helper_table = HelperTable.new
end

Public Instance Methods

execute() click to toggle source
# File lib/captain_hoog/git.rb, line 55
def execute
  if @test_block
    @test_result = @test_block.call
  else
    # run #run
    @run_block.call
  end
  unless @test_result.is_a?(FalseClass) or @test_result.is_a?(TrueClass)
    raise CaptainHoog::Errors::TestResultNotValidError
  end
end
helper(name,&block) click to toggle source
# File lib/captain_hoog/git.rb, line 20
def helper(name,&block)
  return if @helper_table.helper_defined?(name)
  helper_proc = {}
  helper_proc[name] = block
  @helper_table.set(helper_proc)
end
message(color: :red, &blk) click to toggle source
# File lib/captain_hoog/git.rb, line 16
def message(color: :red, &blk)
  @message = CaptainHoog::Message.new(color, blk) if blk
end
method_missing(meth_name, *args, &block) click to toggle source
Calls superclass method
# File lib/captain_hoog/git.rb, line 44
def method_missing(meth_name, *args, &block)
  super unless @helper_table.helper_defined?(meth_name)
  helper = @helper_table[meth_name]
  fail ArgumentError unless helper[meth_name].arity == args.size
  helper[meth_name].call(*args)
end
render_table(rows, headings = []) click to toggle source

Public: Renders a table.

rows - An Array of row contents headings - An Array of headlines

Returns the table as String.

# File lib/captain_hoog/git.rb, line 38
def render_table(rows, headings = [])
  table = ::Terminal::Table.new(headings: headings, rows: rows)

  table.to_s
end
respond_to_missing?(meth_name, include_private = false) click to toggle source
Calls superclass method
# File lib/captain_hoog/git.rb, line 51
def respond_to_missing?(meth_name, include_private = false)
  @helper_table.helper_defined?(meth_name) || super
end
run(&run_block) click to toggle source
# File lib/captain_hoog/git.rb, line 27
def run(&run_block)
  @test_result = true
  @run_block   = run_block
end
test(&test_block) click to toggle source
# File lib/captain_hoog/git.rb, line 10
def test(&test_block)
  if test_block
    @test_block = test_block
  end
end