Class: Qiniu::RS::UP::TmpData

Inherits:
Object
  • Object
show all
Defined in:
lib/qiniu/rs/up.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir, filename) ⇒ TmpData

Returns a new instance of TmpData.



59
60
61
62
63
# File 'lib/qiniu/rs/up.rb', line 59

def initialize(dir, filename)
    @tmpdir = Config.settings[:tmpdir] + File::SEPARATOR + dir
    FileUtils.mkdir_p(@tmpdir) unless File.directory?(@tmpdir)
    @tmpfile = @tmpdir + File::SEPARATOR + filename
end

Instance Method Details

#allObject



72
73
74
# File 'lib/qiniu/rs/up.rb', line 72

def all
    File.exist?(@tmpfile) ? YAML.load_file(@tmpfile) : []
end

#init(values) ⇒ Object



65
66
67
68
69
70
# File 'lib/qiniu/rs/up.rb', line 65

def init(values)
    File.open(@tmpfile, "w") do |f|
        YAML::dump(values, f)
        Utils.debug %Q(Initializing tmpfile: #{@tmpfile})
    end
end

#set(index, value) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/qiniu/rs/up.rb', line 76

def set(index, value)
    values = all
    values[index] = value
    File.open(@tmpfile, "w") do |f|
        YAML::dump(values, f)
        Utils.debug %Q(Updating tmpfile: #{@tmpfile})
    end
end

#sweep!Object



85
86
87
# File 'lib/qiniu/rs/up.rb', line 85

def sweep!
    FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
end