Class: Sparkplug::Cachers::Filesystem
- Inherits:
-
Abstract
- Object
- Abstract
- Sparkplug::Cachers::Filesystem
show all
- Defined in:
- lib/sparkplug/cachers/filesystem.rb
Overview
Reads sparkline data from CSV files. Only the first line of numbers are read. Requests for “/sparks/stats.csv” will pass a data_path of “stats.csv”
Instance Attribute Summary collapse
Attributes inherited from Abstract
#png_path
Instance Method Summary
collapse
Methods inherited from Abstract
#create_sparklines, #serve, #set
Constructor Details
#initialize(directory) ⇒ Filesystem
Returns a new instance of Filesystem.
10
11
12
13
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 10
def initialize(directory)
@directory = directory
super()
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
8
9
10
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 8
def directory
@directory
end
|
Instance Method Details
#exists? ⇒ Boolean
24
25
26
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 24
def exists?
File.file?(@cache_file)
end
|
#png_path=(s) ⇒ Object
15
16
17
18
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 15
def png_path=(s)
@cache_file = File.join(@directory, s)
@png_path = s
end
|
#save(data, options) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 32
def save(data, options)
FileUtils.mkdir_p(File.dirname(@cache_file))
File.open(@cache_file, 'wb') do |png|
png << create_sparklines(data, options)
end
end
|
#size ⇒ Object
20
21
22
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 20
def size
@size ||= File.size(@cache_file)
end
|
#stream ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 39
def stream
::File.open(@cache_file, "rb") do |file|
while part = file.read(8192)
yield part
end
end
end
|
#updated_at ⇒ Object
28
29
30
|
# File 'lib/sparkplug/cachers/filesystem.rb', line 28
def updated_at
@updated_at ||= File.mtime(@cache_file)
end
|