Class: Messagex::Exc

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

Overview

I/O関連例外処理管理クラス

Instance Method Summary collapse

Constructor Details

#initialize(mes) ⇒ Exc

初期化

Parameters:

  • mes (Messagex)

    Messagexクラスのインスタンス



9
10
11
# File 'lib/messagex/exc.rb', line 9

def initialize(mes)
  @mes = mes
end

Instance Method Details

#exc(msg, exit_codestr, block) ⇒ Object

I/O関連例外処理

Parameters:

  • msg (String)

    エラーメッセージ

  • exit_codestr (String)

    終了ステータスの識別名

  • block (Proc)

    Procのインスタンス



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/messagex/exc.rb', line 19

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

ディレクトリ移動失敗例外処理

Parameters:

  • arg1 (String)

    移動しようとしたディレクトリ名

  • block (Proc)

    ブロック引数



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

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

ファイルクローズ失敗例外処理

Parameters:

  • arg1 (String)

    クローズしようとしたファイル名

  • block (Proc)

    ブロック引数



82
83
84
85
86
# File 'lib/messagex/exc.rb', line 82

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

ファイルコピー失敗例外処理

Parameters:

  • arg1 (String)

    コピー元ファイル名

  • arg2 (String)

    コピー先ファイル名

  • block (Proc)

    ブロック引数



105
106
107
108
109
# File 'lib/messagex/exc.rb', line 105

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

ファイル1行読込失敗例外処理

Parameters:

  • arg1 (String)

    読み込もうとしたファイル名

  • block (Proc)

    ブロック引数



71
72
73
74
75
# File 'lib/messagex/exc.rb', line 71

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

ファイルオープン失敗例外処理

Parameters:

  • arg1 (String)

    エラーメッセージに組みこむ値

  • block (Proc)

    ブロック引数



49
50
51
52
53
# File 'lib/messagex/exc.rb', line 49

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

ファイル読込失敗例外処理

Parameters:

  • arg1 (String)

    読み込もうとしたファイル名

  • block (Proc)

    ブロック引数



60
61
62
63
64
# File 'lib/messagex/exc.rb', line 60

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

ファイル書込失敗例外処理

Parameters:

  • arg1 (String)

    書き込もうとしたファイル名

  • block (Proc)

    ブロック引数



93
94
95
96
97
# File 'lib/messagex/exc.rb', line 93

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

ディレクトリ作成失敗例外処理

Parameters:

  • arg1 (String)

    作成しようとしたディレクトリ名

  • block (Proc)

    ブロック引数



116
117
118
119
120
# File 'lib/messagex/exc.rb', line 116

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