Class: Middleman::Store::File

Inherits:
Object
  • Object
show all
Defined in:
lib/store/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

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

#clearObject



30
31
32
# File 'lib/store/file.rb', line 30

def clear
  ::File.delete(*Dir["#{@path}/*"])
end