Class: Messagex::Exc

Inherits:
Object
  • Object
show all
Defined in:
lib/messagex/exc.rb

Instance Method Summary collapse

Constructor Details

#initialize(mes) ⇒ Exc

Returns a new instance of Exc.



3
4
5
# File 'lib/messagex/exc.rb', line 3

def initialize(mes)
  @mes = mes
end

Instance Method Details

#exc(msg, exit_codestr, block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/messagex/exc.rb', line 7

def exc(msg, exit_codestr, block)
  begin
    block.call
  rescue IOError => e
    @mes.output_exception(e)
    @mes.output_fatal(msg)
    exit(@mes.ec(exit_codestr))
  rescue SystemCallError => e
    @mes.output_exception(e)
    @mes.output_fatal(msg)
    exit(@mes.ec(exit_codestr))
  end
end

#exc_change_directory(arg1, &block) ⇒ Object



21
22
23
24
25
# File 'lib/messagex/exc.rb', line 21

def exc_change_directory(arg1, &block)
  msg = "Can't change directory to |#{arg1}|"
  exit_codestr = "EXIT_CODE_CANNOT_CHANGE_DIRECTORY"
  exc(msg, exit_codestr, block)
end

#exc_file_close(arg1, &block) ⇒ Object



45
46
47
48
49
# File 'lib/messagex/exc.rb', line 45

def exc_file_close(arg1, &block)
  msg = "Cannot close file #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_OPEN_FILE"
  exc(msg, exit_codestr, block)
end

#exc_file_copy(arg1, arg2, &block) ⇒ Object



57
58
59
60
61
# File 'lib/messagex/exc.rb', line 57

def exc_file_copy(arg1, arg2, &block)
  msg = "Can't copy file from #{arg1} to #{arg2}"
  exit_codestr = "EXIT_CODE_CANNOT_COPY_FILE"
  exc(msg, exit_codestr, block)
end

#exc_file_gets(arg1, &block) ⇒ Object



39
40
41
42
43
# File 'lib/messagex/exc.rb', line 39

def exc_file_gets(arg1, &block)
  msg = "Cannot read file #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_READ_FILE"
  exc(msg, exit_codestr, block)
end

#exc_file_open(arg1, &block) ⇒ Object



27
28
29
30
31
# File 'lib/messagex/exc.rb', line 27

def exc_file_open(arg1, &block)
  msg = "Cannot open file #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_OPEN_FILE"
  exc(msg, exit_codestr, block)
end

#exc_file_read(arg1, &block) ⇒ Object



33
34
35
36
37
# File 'lib/messagex/exc.rb', line 33

def exc_file_read(arg1, &block)
  msg = "Cannot read file #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_READ_FILE"
  exc(msg, exit_codestr, block)
end

#exc_file_write(arg1, &block) ⇒ Object



51
52
53
54
55
# File 'lib/messagex/exc.rb', line 51

def exc_file_write(arg1, &block)
  msg = "Cannot write file #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_WRITE_FILE"
  exc(msg, exit_codestr, block)
end

#exc_make_directory(arg1, &block) ⇒ Object



63
64
65
66
67
# File 'lib/messagex/exc.rb', line 63

def exc_make_directory(arg1, &block)
  msg = "Can't make directory to #{arg1}"
  exit_codestr = "EXIT_CODE_CANNOT_MAKE_DIRECTORY"
  exc(msg, exit_codestr, block)
end