Class: Middleman::Store::File
- Inherits:
-
Object
- Object
- Middleman::Store::File
- Defined in:
- lib/store/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #clear ⇒ Object
-
#initialize(path) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
10 11 12 13 14 15 16 17 |
# File 'lib/store/file.rb', line 10 def initialize(path) @path = path.chomp('/') unless ::File.exists? path FileUtils.mkdir_p(path) end end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/store/file.rb', line 8 def path @path end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 |
# File 'lib/store/file.rb', line 19 def [](key) return unless ::File.exist?(path_from_key(key)) Marshal.load(::File.read(path_from_key(key))) end |
#[]=(key, val) ⇒ Object
24 25 26 27 28 |
# File 'lib/store/file.rb', line 24 def []=(key, val) ::File.open(path_from_key(key), 'w') do |f| f.write(Marshal.dump(val)) end end |
#clear ⇒ Object
30 31 32 |
# File 'lib/store/file.rb', line 30 def clear ::File.delete(*Dir["#{@path}/*"]) end |