Sha256: 161bc4ecc58244d40e1d9ba436e1e75e07d629c068fa857bd602068cf8a1751c

Contents?: true

Size: 760 Bytes

Versions: 6

Compression:

Stored size: 760 Bytes

Contents

# -*- coding: UTF-8 -*-

require 'tempfile'

module MJ; module Tools

    # 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.
    class TmpFileEditor

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

        def editor()
            "gvim -f"
        end

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

        def path()
            @file.path()
        end

    end


end; end # module MJ::Tools

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
build-tool-0.6.3 lib/mj/tools/editor.rb
build-tool-0.6.2 lib/mj/tools/editor.rb
build-tool-0.6.1 lib/mj/tools/editor.rb
build-tool-0.6.0 lib/mj/tools/editor.rb
build-tool-0.6.0.rc2 lib/mj/tools/editor.rb
build-tool-0.6.0.rc1 lib/mj/tools/editor.rb