Class: Moneta::Adapters::BasicFile
- Inherits:
-
Object
- Object
- Moneta::Adapters::BasicFile
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/basic_file.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ BasicFile
constructor
A new instance of BasicFile.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ BasicFile
Returns a new instance of BasicFile.
25 26 27 28 29 30 |
# File 'lib/moneta/adapters/basic_file.rb', line 25 def initialize( = {}) @namespace = [:namespace] @directory = ::File.join([:path], @namespace.to_s) ensure_directory_created(@directory) end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 39 40 |
# File 'lib/moneta/adapters/basic_file.rb', line 36 def [](key) if ::File.exist?(path(key)) raw_get(key) end end |
#clear ⇒ Object
55 56 57 58 |
# File 'lib/moneta/adapters/basic_file.rb', line 55 def clear(*) FileUtils.rm_rf(@directory) FileUtils.mkdir(@directory) end |
#delete(key) ⇒ Object
49 50 51 52 53 |
# File 'lib/moneta/adapters/basic_file.rb', line 49 def delete(key, *) value = self[key] delete!(key) value end |
#key?(key) ⇒ Boolean
32 33 34 |
# File 'lib/moneta/adapters/basic_file.rb', line 32 def key?(key, *) !self[key].nil? end |
#store(key, value) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/moneta/adapters/basic_file.rb', line 42 def store(key, value, *) ensure_directory_created(::File.dirname(path(key))) ::File.open(path(key), "w") do |file| file.puts(serialize(value)) end end |