Class: Resque::Reports::CacheFile

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/reports/cache_file.rb

Constant Summary collapse

DEFAULT_EXPIRE_TIME =
86400
DEFAULT_CODING =
'utf-8'

Instance Method Summary collapse

Constructor Details

#initialize(dir, filename, options = {}) ⇒ CacheFile

TODO: Description!



10
11
12
13
14
15
16
17
# File 'lib/resque/reports/cache_file.rb', line 10

def initialize(dir, filename, options = {})
  @dir = dir
  @filename = File.join(dir, filename)

  # options
  @coding = options[:coding] || DEFAULT_CODING
  @expiration_time = options[:expire_in] || DEFAULT_EXPIRE_TIME
end

Instance Method Details

#exists?Boolean Also known as: ready?

Returns:

  • (Boolean)


19
20
21
# File 'lib/resque/reports/cache_file.rb', line 19

def exists?
  File.exists?(@filename)
end

#filenameObject



24
25
26
27
# File 'lib/resque/reports/cache_file.rb', line 24

def filename
  raise "File doesn't exists, check for its existance before" unless exists?
  @filename
end

#openObject



29
30
31
32
33
34
35
36
37
# File 'lib/resque/reports/cache_file.rb', line 29

def open
  prepare_cache_dir

  remove_unfinished_on_error do
    File.open(@filename, @coding) do |file|
      yield file
    end
  end
end