Class: CaptainHoog::Git
- Inherits:
-
Object
show all
- Defined in:
- lib/captain_hoog/git.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Git
Returns a new instance of Git.
6
7
8
|
# File 'lib/captain_hoog/git.rb', line 6
def initialize
@helper_table = HelperTable.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth_name, *args, &block) ⇒ Object
44
45
46
47
48
49
|
# 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
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
4
5
6
|
# File 'lib/captain_hoog/git.rb', line 4
def env
@env
end
|
Instance Method Details
#execute ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/captain_hoog/git.rb', line 55
def execute
if @test_block
@test_result = @test_block.call
else
@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) ⇒ Object
20
21
22
23
24
25
|
# 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) ⇒ Object
16
17
18
|
# File 'lib/captain_hoog/git.rb', line 16
def message(color: :red, &blk)
@message = CaptainHoog::Message.new(color, blk) if blk
end
|
#render_table(rows, headings = []) ⇒ Object
Public: Renders a table.
rows - An Array of row contents headings - An Array of headlines
Returns the table as String.
38
39
40
41
42
|
# 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) ⇒ Boolean
51
52
53
|
# 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) ⇒ Object
27
28
29
30
|
# File 'lib/captain_hoog/git.rb', line 27
def run(&run_block)
@test_result = true
@run_block = run_block
end
|
#test(&test_block) ⇒ Object
10
11
12
13
14
|
# File 'lib/captain_hoog/git.rb', line 10
def test(&test_block)
if test_block
@test_block = test_block
end
end
|