Class: Editserver::Editor

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

Direct Known Subclasses

Emacs, Vim

Constant Summary collapse

@@terminal =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.commandObject

Returns the value of attribute command.



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

def command
  @command
end

Class Method Details

.define_editor(editor, *params) ⇒ Object



8
9
10
# File 'lib/editserver/editor.rb', line 8

def define_editor editor, *params
  @command = [%x(which #{editor}).chomp, *params]
end

.terminalObject



14
15
16
# File 'lib/editserver/editor.rb', line 14

def terminal
  @@terminal
end

.terminal=(str) ⇒ Object



18
19
20
21
22
23
# File 'lib/editserver/editor.rb', line 18

def terminal= str
  @@terminal = case str
  when String   then str.shellsplit
  when NilClass then nil
  end
end

Instance Method Details

#edit(file) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/editserver/editor.rb', line 30

def edit file
  cmd = self.class.command

  if not File.executable? cmd.first
    File.open(file, 'w') { |f| f.write "Editor not found: #{cmd.first.inspect}" }
    return
  end

  out = %x(#{(cmd + [file]).shelljoin} 2>&1).chomp

  if $?.exitstatus.zero?
    out
  else
    raise EditError, out
  end
end

#terminalObject

self



26
27
28
# File 'lib/editserver/editor.rb', line 26

def terminal
  @@terminal
end