Class: Md2site::StatusFile
- Inherits:
-
Object
- Object
- Md2site::StatusFile
- Defined in:
- lib/md2site/statusfile.rb
Overview
ダウンロードステータスファイルクラス
Instance Attribute Summary collapse
-
#baseurl ⇒ String
ダウンロード先ホストのURL.
-
#fname ⇒ String
ダウンロードヘッダ一覧ファイル名.
-
#fpath ⇒ String
ダウンロードヘッダ一覧ファイルへのパス.
-
#last_contents_path ⇒ Object
ダウンロード保存先ディレクトリへのパス.
-
#last_datetime ⇒ String
ダウンロード開始日時.
Instance Method Summary collapse
-
#get_statusfile(path) ⇒ String
ダウンロードステータスファイルの内容の取得.
-
#initialize(path, absolutepath_root, baseurl, mes) ⇒ StatusFile
constructor
初期化.
-
#output(path, content) ⇒ void
ダウンロードステータスファイル出力.
-
#print ⇒ void
ダウンロードステータスファイルの内容の出力(デバッグ用).
-
#update ⇒ void
ダウンロードステータスファイル更新.
Constructor Details
#initialize(path, absolutepath_root, baseurl, mes) ⇒ StatusFile
初期化
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/md2site/statusfile.rb', line 24 def initialize(path, absolutepath_root, baseurl, mes) @path = path @absolutepath_root_pn = Pathname.new(absolutepath_root) @baseurl = baseurl @mes = mes mes.add_exitcode("EXIT_CODE_CANNOT_ANALYZE_YAMLFILE") mes.add_exitcode("EXIT_CODE_CANNOT_DUMP_TO_YAML") content = get_statusfile(@path) if content && !content.strip.empty? obj = Filex::Filex.load_yaml(content, @mes) @baseurl = obj[:baseurl] @fname = obj[:fname] @fpath = obj[:fpath] @absolutepath_fpath_pn = Pathname.new(get_absolute_path(@fpath)) @last_datetime = obj[:last_datetime] @last_contents_path = obj[:last_contents_path] @absolutepath_last_contents_path_pn = Pathname.new(get_absolute_path(@last_contents_path)) else @baseurl = @baseurl @fname = nil @fpath = nil @last_datetime = nil @last_contents_path = nil end end |
Instance Attribute Details
#baseurl ⇒ String
Returns ダウンロード先ホストのURL.
8 9 10 |
# File 'lib/md2site/statusfile.rb', line 8 def baseurl @baseurl end |
#fname ⇒ String
Returns ダウンロードヘッダ一覧ファイル名.
10 11 12 |
# File 'lib/md2site/statusfile.rb', line 10 def fname @fname end |
#fpath ⇒ String
Returns ダウンロードヘッダ一覧ファイルへのパス.
12 13 14 |
# File 'lib/md2site/statusfile.rb', line 12 def fpath @fpath end |
#last_contents_path ⇒ Object
ダウンロード保存先ディレクトリへのパス
16 17 18 |
# File 'lib/md2site/statusfile.rb', line 16 def last_contents_path @last_contents_path end |
#last_datetime ⇒ String
Returns ダウンロード開始日時.
14 15 16 |
# File 'lib/md2site/statusfile.rb', line 14 def last_datetime @last_datetime end |
Instance Method Details
#get_statusfile(path) ⇒ String
Note:
引数pathがnilであれば例外発生
ダウンロードステータスファイルの内容の取得
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/md2site/statusfile.rb', line 106 def get_statusfile(path) unless path raise end content = nil if File.exist?(path) @mes.exc_file_read(path) { content = File.read(path) } end content end |
#output(path, content) ⇒ void
This method returns an undefined value.
ダウンロードステータスファイル出力
61 62 63 64 65 66 |
# File 'lib/md2site/statusfile.rb', line 61 def output(path, content) File.open(path, "w") do |ofile| ofile.puts(content) ofile.flush end end |
#print ⇒ void
This method returns an undefined value.
ダウンロードステータスファイルの内容の出力(デバッグ用)
122 123 124 125 126 127 128 |
# File 'lib/md2site/statusfile.rb', line 122 def print @mes.output_info("baseurl=#{@baseurl}") @mes.output_info("fname=#{@fname}") @mes.output_info("fpath=#{@fpath}") @mes.output_info("last_datetime=#{@last_datetime}") @mes.output_info("last_contents_path=#{@last_contents_path}") end |
#update ⇒ void
Note:
YAML形式に変換できなければダウンロードステータスファイルを更新しない
This method returns an undefined value.
ダウンロードステータスファイル更新
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/md2site/statusfile.rb', line 73 def update if @fpath @absolutepath_fpath_pn = Pathname.new(get_absolute_path(@fpath)) @fpath = @absolutepath_fpath_pn.relative_path_from(@absolutepath_root_pn).to_s else @fpath = "" end if @last_contents_path @absolutepath_last_contents_path_pn = Pathname.new(get_absolute_path(@last_contents_path)) @last_contents_path = @absolutepath_last_contents_path_pn.relative_path_from(@absolutepath_root_pn).to_s else @last_contents_path = "" end hs = { baseurl: @baseurl, fname: @fname, fpath: @fpath, last_datetime: @last_datetime, last_contents_path: @last_contents_path } begin content = YAML.dump(hs) rescue Error => e @mes.output_exception(e) exit(@mes.ec("EXIT_CODE_CANNOT_DUMP_TO_YAML")) end return unless content @mes.exc_file_write(@path) { output(@path, content) } end |