class MoreHoliday::Cache::File
Attributes
data[R]
file_name[R]
folder_path[R]
Public Class Methods
clear!()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 43 def self.clear! !!FileUtils.rm_rf(::File.join("tmp", "cache")) end
new(file_name:, folder_path: @file_name = file_name)
click to toggle source
# File lib/more_holiday/cache/file.rb, line 8 def initialize file_name:, folder_path: @file_name = file_name @folder_path = ::File.join(cache_base_path, folder_path) end
Public Instance Methods
exist?()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 30 def exist? ::File.exists?(file_path) and still_valid? end
file_path()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 13 def file_path ::File.join(folder_path, file_name) end
read()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 17 def read return nil if !exist? or !still_valid? ::File.read(file_path) rescue raise FileCacheReadError, "An error occurred while reading from file cache." end
resolve(function)
click to toggle source
# File lib/more_holiday/cache/file.rb, line 34 def resolve function if exist? read else write function.call data end end
write(data)
click to toggle source
# File lib/more_holiday/cache/file.rb, line 24 def write data @data = data FileUtils::mkdir_p(folder_path) !!::File.write(file_path, data) end
Private Instance Methods
cache_base_path()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 49 def cache_base_path ::File.join("tmp", "cache") end
still_valid?()
click to toggle source
# File lib/more_holiday/cache/file.rb, line 53 def still_valid? # TODO: implement useful invalidation rule true end