Class: Db2c::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/db2c/editor.rb

Class Method Summary collapse

Class Method Details

.command(editor) ⇒ Object



27
28
29
30
# File 'lib/db2c/editor.rb', line 27

def self.command editor
  return ["emacs", "-nw"] if editor =~ /^emacs/
  ["vi"]
end

.edit(editor) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/db2c/editor.rb', line 6

def self.edit editor
  puts "editor #{editor}" if $DB2CDBG
  @file ||= Tempfile.new(["db2_tempfile", ".sql"])
  mtime = File.stat(@file.path).mtime

  args = []
  args << command(editor)
  args << @file.path
  args.flatten!

  @file.close

  puts "editor args: #{args.inspect}" if $DB2CDBG

  system(*args)

  if mtime < File.stat(@file.path).mtime
    return IO.read(@file.path)
  end
end