Class: MJ::Tools::TmpFileEditor
- Inherits:
-
Object
- Object
- MJ::Tools::TmpFileEditor
- 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
- #edit ⇒ Object
- #editor ⇒ Object
-
#initialize(content) ⇒ TmpFileEditor
constructor
A new instance of TmpFileEditor.
- #path ⇒ Object
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
#edit ⇒ Object
22 23 24 25 |
# File 'lib/mj/tools/editor.rb', line 22 def edit() system( "#{editor()} #{@file.path}" ) return $? == 0 end |
#editor ⇒ Object
18 19 20 |
# File 'lib/mj/tools/editor.rb', line 18 def editor() "gvim -f" end |
#path ⇒ Object
27 28 29 |
# File 'lib/mj/tools/editor.rb', line 27 def path() @file.path() end |