Class: GHI::Editor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Editor

Returns a new instance of Editor.



6
7
8
# File 'lib/ghi/editor.rb', line 6

def initialize filename
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/ghi/editor.rb', line 5

def filename
  @filename
end

Instance Method Details

#gets(prefill) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/ghi/editor.rb', line 10

def gets prefill
  File.open path, 'a+' do |f|
    f << prefill if File.zero? path
    f.rewind
    system "#{editor} #{f.path}"
    return File.read(f.path).gsub(/(?:^#.*$\n?)+\s*\z/, '').strip
  end
end


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

def unlink message = nil
  File.delete path
  abort message if message
end