Top Level Namespace

Defined Under Namespace

Modules: Configer, Librr, ServerStarter Classes: DelayIterator, MyThor, Settings

Instance Method Summary collapse

Instance Method Details

#fix_encoding(text) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/librr/lib.rb', line 33

def fix_encoding text
  # solution copy from:
  # http://stackoverflow.com/questions/11375342/stringencode-not-fixing-invalid-byte-sequence-in-utf-8-error
  text
    .encode('UTF-16', undef: :replace, invalid: :replace, replace: "")
    .encode('UTF-8')
end

#kill_process_by_file(file) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/librr/lib.rb', line 41

def kill_process_by_file file
  begin
    pid = File.read(file).to_i
    Process.kill 'TERM', pid if pid > 0
    File.delete file
  rescue
  end
end

#redirect_stdObject



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/librr/lib.rb', line 1

def redirect_std
  stdin = $stdin.dup
  stdout = $stdout.dup
  stderr = $stderr.dup

  ri, wi = IO::pipe
  ro, wo = IO::pipe
  re, we = IO::pipe

  $stdin.reopen ri
  $stdout.reopen wo
  $stderr.reopen we

  yield

  $stdin.reopen stdin
  $stdout.reopen stdout
  $stderr.reopen stderr
  [wi, ro, re]
end

#redirect_std_to_file(filename) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/librr/lib.rb', line 22

def redirect_std_to_file(filename)
  f = File.open(filename, 'a+')
  f.sync = true

  $stdout.reopen f
  $stderr.reopen f

  yield
end