Class: AppFile

Inherits:
Object show all
Defined in:
lib/tecsgen/core/generate.rb

Overview

Appendable File(追記可能ファイル)

Constant Summary collapse

@@file_name_list =

開いたファイルのリスト

{}

Class Method Summary collapse

Class Method Details

.open(name) ⇒ Object



5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
# File 'lib/tecsgen/core/generate.rb', line 5098

def self.open(name)
  if $force_overwrite
    real_name = name
  else
    real_name = name + ".tmp"
  end

# 2.0
  mode = ":" + $Ruby19_File_Encode

  # 既に開いているか?
  if @@file_name_list[name]
# 2.0
    mode = "a" + mode
    # 追記モードで開く
    file = File.open(real_name, mode)
  else
# 2.0
    mode = "w" + mode
    # 新規モードで開く(既にあれば、サイズを0にする)
    file = File.open(real_name, mode)
    @@file_name_list[name] = true
  end
  # File クラスのオブジェクトを返す
  return file
end

.updateObject



5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
# File 'lib/tecsgen/core/generate.rb', line 5125

def self.update
  if $force_overwrite
    return
  end

  @@file_name_list.each{|name, boo|
    b_identical = false
    if File.readable? name
      old_lines = File.readlines name
      new_lines = File.readlines name + ".tmp"
      if old_lines.length == new_lines.length
        i = 0
        len = old_lines.length
        while i < len
          if old_lines[i] != new_lines[i]
            break
          end
          i += 1
        end
        if i == len
          b_identical = true
        end
      end
    end
    if b_identical == false
      if $verbose
        print "#{name} updated\n"
        print "renaming '#{name}.tmp' => '#{name}'\n"
      end
      File.rename name + ".tmp", name
    else
      if $verbose
        print "#{name} not updated\n"
      end
      File.delete name + ".tmp"
    end
  }
end