Class: Rack::PageSpeed::Store::Disk

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/pagespeed/store/disk.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.tmpdir) ⇒ Disk

Returns a new instance of Disk.

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/rack/pagespeed/store/disk.rb', line 6

def initialize path = Dir.tmpdir
  raise ArgumentError, "#{path} is not a directory" unless File.directory? path
  @path = path
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
14
# File 'lib/rack/pagespeed/store/disk.rb', line 11

def [] key
  path = "#{@path}/rack-pagespeed-#{key}"
  File.read path if File.exists? path
end

#[]=(key, value) ⇒ Object



16
17
18
19
# File 'lib/rack/pagespeed/store/disk.rb', line 16

def []= key, value
  File.open("#{@path}/rack-pagespeed-#{key}", 'w') { |file| file << value }
  true
end