Class: ButterflyNet::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/butterfly_net/file_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, start_index) ⇒ FileWriter

Returns a new instance of FileWriter.



7
8
9
10
# File 'lib/butterfly_net/file_writer.rb', line 7

def initialize(file_name, start_index)
  @file_name = file_name
  @start_index = start_index
end

Instance Attribute Details

#end_indexObject

Returns the value of attribute end_index.



4
5
6
# File 'lib/butterfly_net/file_writer.rb', line 4

def end_index
  @end_index
end

#start_indexObject (readonly)

Returns the value of attribute start_index.



5
6
7
# File 'lib/butterfly_net/file_writer.rb', line 5

def start_index
  @start_index
end

Instance Method Details

#closeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/butterfly_net/file_writer.rb', line 17

def close
  lines = Readline::HISTORY.to_a
  @end_index ||= Readline::HISTORY.size - 3 # in case of no call to 'bn_close'
  if @end_index < 0 || lines[@start_index..@end_index].empty?
    puts "butterfly_net: #{@file_name} closed, no file written to disk"
    false
  else
    adapter = TestUnitAdapter.new

    lines[@start_index..@end_index].each do |line|
      adapter.add_command(line)
    end

    adapter.create_file(@file_name)

    puts "butterfly_net: #{@file_name} closed after Readline::HISTORY ##{@end_index}"
    true
  end
rescue Exception => msg
  puts "butterfly_net:  Error generating tests: #{msg}"
  false
end

#new_assertion_setObject



12
13
14
# File 'lib/butterfly_net/file_writer.rb', line 12

def new_assertion_set

end