Class: Editor
- Inherits:
-
Object
- Object
- Editor
- Defined in:
- lib/editor.rb
Constant Summary collapse
- DEFAULT_EDITOR =
"vi"
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #edit_file ⇒ Object
-
#initialize(path, command) ⇒ Editor
constructor
A new instance of Editor.
- #note(string) ⇒ Object
- #puts(string) ⇒ Object
Constructor Details
#initialize(path, command) ⇒ Editor
Returns a new instance of Editor.
12 13 14 15 16 |
# File 'lib/editor.rb', line 12 def initialize(path, command) @path = path @command = command || DEFAULT_EDITOR @closed = false end |
Class Method Details
Instance Method Details
#close ⇒ Object
28 29 30 |
# File 'lib/editor.rb', line 28 def close @closed = true end |
#edit_file ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/editor.rb', line 32 def edit_file file.close editor_argv = Shellwords.shellsplit(@command) + [@path.to_s] unless @closed or system(*editor_argv) raise "There was a problem with the editor '#{ @command }'." end remove_notes(File.read(@path)) end |
#note(string) ⇒ Object
23 24 25 26 |
# File 'lib/editor.rb', line 23 def note(string) return if @closed string.each_line { |line| file.puts("# #{ line }") } end |
#puts(string) ⇒ Object
18 19 20 21 |
# File 'lib/editor.rb', line 18 def puts(string) return if @closed file.puts(string) end |