Class: Dial::Storage::FileAdapter
- Inherits:
-
Object
- Object
- Dial::Storage::FileAdapter
- Defined in:
- lib/dial/storage/file_adapter.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(options = {}) ⇒ FileAdapter
constructor
A new instance of FileAdapter.
- #store(key, data, ttl: nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FileAdapter
Returns a new instance of FileAdapter.
9 10 11 12 13 14 15 16 |
# File 'lib/dial/storage/file_adapter.rb', line 9 def initialize = {} @ttl = [:ttl] || STORAGE_TTL @profile_dir = ::Rails.root.join VERNIER_PROFILE_OUT_RELATIVE_DIRNAME FileUtils.mkdir_p @profile_dir rescue Errno::ENOENT FileUtils.mkdir_p File.dirname @profile_dir FileUtils.mkdir_p @profile_dir end |
Instance Method Details
#cleanup ⇒ Object
31 32 33 |
# File 'lib/dial/storage/file_adapter.rb', line 31 def cleanup expired_files("#{@profile_dir}/*").each { |file| File.delete file rescue nil } end |
#delete(key) ⇒ Object
27 28 29 |
# File 'lib/dial/storage/file_adapter.rb', line 27 def delete key delete_profile key end |
#fetch(key) ⇒ Object
23 24 25 |
# File 'lib/dial/storage/file_adapter.rb', line 23 def fetch key fetch_profile key end |
#store(key, data, ttl: nil) ⇒ Object
18 19 20 21 |
# File 'lib/dial/storage/file_adapter.rb', line 18 def store key, data, ttl: nil ttl ||= @ttl store_profile key, data, ttl end |