Class: Flist::Dbutil::FlistzMgr
- Inherits:
-
Object
- Object
- Flist::Dbutil::FlistzMgr
- Includes:
- Ykutils::DebugUtils
- Defined in:
- lib/flist/dbutil/flistzmgr.rb
Overview
ファイル情報マネージャ
Instance Method Summary collapse
-
#add(dir_id, level, kind, repo, path, project, desc, comment, atime, ctime, mtime) ⇒ Object
ファイル情報追加・更新 DBに未登録の時は追加し、登録済みの時は更新する.
-
#initialize(encx, db_encoding, register_time) ⇒ FlistzMgr
constructor
A new instance of FlistzMgr.
-
#post_process ⇒ Object
後処理.
-
#post_process_for_dir_id(dir_id) ⇒ Object
後処理(ディレクトリID) DBに登録済データのうち、ハッシュに存在しないデータをInvalidflistzに登録する.
Constructor Details
#initialize(encx, db_encoding, register_time) ⇒ FlistzMgr
Returns a new instance of FlistzMgr.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flist/dbutil/flistzmgr.rb', line 12 def initialize(encx, db_encoding, register_time) # 指定エンコーディングの基づいたパス操作 @encx = encx # DBのエンコーディング @db_encoding = db_encoding # DB接続時のタイムスタンプ @register_time = register_time # DBに登録・更新したファイル情報をのハッシュ # キーはパス @hs_by_path = {} # DBに登録・更新したファイル情報のハッシュ # キーはファイル情報のobject_id @hs_by_id = {} # DBに登録・更新したファイル情報に対応するディレクトリID @set_of_dir_id = Set.new end |
Instance Method Details
#add(dir_id, level, kind, repo, path, project, desc, comment, atime, ctime, mtime) ⇒ Object
ファイル情報追加・更新 DBに未登録の時は追加し、登録済みの時は更新する
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/flist/dbutil/flistzmgr.rb', line 31 def add(dir_id, level, kind, repo, path, project, desc, comment, atime, ctime, mtime) d_puts 'Flist::Dbutil::FlistzMgr add' # pathをDBのエンコーディングに変換する path_conv = @encx.convert(path, @db_encoding) # パスが表すファイル情報をハッシュから得る flistz = @hs_by_path[path_conv] # パスに対応するファイル情報が見つかれば何もしない return flistz if flistz # FlistzのViewから、dir_idとパスで指定したファイル情報を得る cur_flistz = Currentflistz.where(dir_id: dir_id, path: path_conv).limit(1) if cur_flistz.size.zero? # 見つからなければ、新たにファイル情報をDBに登録する begin d_puts '#### FlistzMgr' d_puts "dir_id=#{dir_id}" d_puts "level=#{level}" d_puts "kind=#{kind}" d_puts "repo=#{repo}" d_puts "path=#{path_conv}" d_puts "project=#{project}" d_puts "desc=#{desc}" d_puts "comment=#{comment}" d_puts "atime=#{atime}" d_puts "ctime=#{ctime}" d_puts "mtime=#{mtime}" d_puts "@register_time=#{@register_time}" d_puts '#### FlistzMgr End' flistz = Flistz.create(dir_id: dir_id, level: level, kind: kind, repo: repo, path: path_conv, project: project, desc: desc, comment: comment, atime: atime, ctime: ctime, mtime: mtime, start_datetime: @register_time) rescue StandardError => e p e.class p e. pp e.backtrace flistz = nil end else # DBから見つかれば、最初に見つけたファイル情報を更新する # current_flistz = cur_flistz.first.flistz current_flistz = cur_flistz[0].flistz hs = { atime: atime, ctime: ctime, mtime: mtime, repo: repo, project: project, desc: desc, comment: comment } value_hs = hs.each_with_object({}) do |item, hsx| hsx[item[0]] = item[1] if current_flistz[item[0]] != item[1] end current_flistz.update(value_hs) if value_hs.size.positive? flistz = current_flistz end # DBに登録・更新したファイル情報をハッシュに格納 if flistz @hs_by_path[path] = flistz @hs_by_id[flistz.object_id] = flistz @set_of_dir_id.add(dir_id) end flistz end |
#post_process ⇒ Object
後処理
94 95 96 97 98 |
# File 'lib/flist/dbutil/flistzmgr.rb', line 94 def post_process @set_of_dir_id.each do |dir_id| post_process_for_dir_id(dir_id) end end |
#post_process_for_dir_id(dir_id) ⇒ Object
後処理(ディレクトリID) DBに登録済データのうち、ハッシュに存在しないデータをInvalidflistzに登録する
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/flist/dbutil/flistzmgr.rb', line 102 def post_process_for_dir_id(dir_id) h_ids = Currentflistz.where(dir_id: dir_id).pluck(:org_id) t_ids = @hs_by_id.keys ids = h_ids - t_ids return unless ids.size.positive? ids.each do |idx| Invalidflistz.create(org_id: idx, end_datetime: @register_time) end end |