Class: MJ::Tools::TmpFileEditor

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

Overview

A class that puts the given content in a tmpfile, opens an editor for the user to play with it. After the user closed the editor it will give back the new content.

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ TmpFileEditor

Returns a new instance of TmpFileEditor.



11
12
13
14
15
16
# File 'lib/mj/tools/editor.rb', line 11

def initialize( content )
    @file = Tempfile.new( [ 'configuration', '.yaml' ] )
    # First write the old content into the file
    @file.write( content )
    @file.close()
end

Instance Method Details

#editObject



22
23
24
25
# File 'lib/mj/tools/editor.rb', line 22

def edit()
    system( "#{editor()} #{@file.path}" )
    return $? == 0
end

#editorObject



18
19
20
# File 'lib/mj/tools/editor.rb', line 18

def editor()
    "gvim -f"
end

#pathObject



27
28
29
# File 'lib/mj/tools/editor.rb', line 27

def path()
    @file.path()
end