Class: T::Editor

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

Class Method Summary collapse

Class Method Details

.edit(path) ⇒ Object



20
21
22
# File 'lib/t/editor.rb', line 20

def edit(path)
  system(Shellwords.join([editor, path]))
end

.editorObject



24
25
26
# File 'lib/t/editor.rb', line 24

def editor
  ENV['VISUAL'] || ENV['EDITOR'] || system_editor
end

.getsObject



7
8
9
10
11
12
13
14
# File 'lib/t/editor.rb', line 7

def gets
  file = tempfile
  edit(file.path)
  File.read(file).strip
ensure
  file.close
  file.unlink
end

.system_editorObject



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

def system_editor
  RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'notepad' : 'vi'
end

.tempfileObject



16
17
18
# File 'lib/t/editor.rb', line 16

def tempfile
  Tempfile.new('TWEET_EDITMSG')
end