Module: DTAS::EditClient

Defined in:
lib/dtas/edit_client.rb

Overview

common code between dtas-sourceedit and dtas-sinkedit

Instance Method Summary collapse

Instance Method Details

#client_socketObject


20
21
22
23
24
25
# File 'lib/dtas/edit_client.rb', line 20

def client_socket
  DTAS::UNIXClient.new
rescue
  e = "DTAS_PLAYER_SOCK=#{DTAS::UNIXClient.default_path}"
  abort "dtas-player not running on #{e}"
end

#editorObject

:nodoc:


11
12
13
14
15
16
17
18
# File 'lib/dtas/edit_client.rb', line 11

def editor
  %w(VISUAL EDITOR).each do |key|
    v = ENV[key] or next
    v.empty? and next
    return v
  end
  'vi'.freeze
end

#tmpyamlObject


27
28
29
30
31
32
# File 'lib/dtas/edit_client.rb', line 27

def tmpyaml
  tmp = Tempfile.new(%W(#{File.basename($0)} .yml))
  tmp.sync = true
  tmp.binmode
  tmp
end

#update_cmd_env(cmd, orig, updated) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dtas/edit_client.rb', line 34

def update_cmd_env(cmd, orig, updated)
  if env = updated["env"]
    env.each do |k,v|
      cmd << (v.nil? ? "env##{k}" : "env.#{k}=#{v}")
    end
  end

  # remove deleted env
  if orig_env = orig["env"]
    env ||= {}
    deleted_keys = orig_env.keys - env.keys
    deleted_keys.each { |k| cmd << "env##{k}" }
  end
end