Class: Completely::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/completely/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script: nil, script_path: nil, function_name:) ⇒ Tester

Returns a new instance of Tester.



8
9
10
# File 'lib/completely/tester.rb', line 8

def initialize(script: nil, script_path: nil, function_name: )
  @script, @script_path, @function_name = script, script_path, function_name
end

Instance Attribute Details

#complineObject (readonly)

Returns the value of attribute compline.



6
7
8
# File 'lib/completely/tester.rb', line 6

def compline
  @compline
end

#cwordObject (readonly)

Returns the value of attribute cword.



6
7
8
# File 'lib/completely/tester.rb', line 6

def cword
  @cword
end

#function_nameObject (readonly)

Returns the value of attribute function_name.



6
7
8
# File 'lib/completely/tester.rb', line 6

def function_name
  @function_name
end

#scriptObject (readonly)

Returns the value of attribute script.



6
7
8
# File 'lib/completely/tester.rb', line 6

def script
  @script
end

#script_pathObject (readonly)

Returns the value of attribute script_path.



6
7
8
# File 'lib/completely/tester.rb', line 6

def script_path
  @script_path
end

Instance Method Details

#test(compline) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/completely/tester.rb', line 12

def test(compline)
  Tempfile.create "completely-tester" do |f|
    f << tester_script(compline)
    f.flush
    `bash #{f.path}`
  end.split "\n"
end

#tester_script(compline) ⇒ Object



20
21
22
23
# File 'lib/completely/tester.rb', line 20

def tester_script(compline)
  set_compline_vars compline
  ERB.new(template, trim_mode: '%-').result(binding)
end