Class: Fluoride::Collector::Storage::FS
Instance Attribute Summary
#collection_type, #record
Instance Method Summary
collapse
#initialize, #record_yaml, #thread_locals
Instance Method Details
#directory ⇒ Object
7
8
9
|
# File 'lib/fluoride-collector/storage/fs.rb', line 7
def directory
@config.directory
end
|
#storage_file ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/fluoride-collector/storage/fs.rb', line 36
def storage_file
FileUtils.mkdir_p(File::dirname(storage_path))
return if storage_used > storage_limit
File::open(storage_path, "a") do |file|
yield file
end
end
|
#storage_limit ⇒ Object
11
12
13
|
# File 'lib/fluoride-collector/storage/fs.rb', line 11
def storage_limit
@config.storage_limit
end
|
#storage_path ⇒ Object
32
33
34
|
# File 'lib/fluoride-collector/storage/fs.rb', line 32
def storage_path
thread_locals[collection_type] ||= File::join(directory, "#{collection_type}-#{Process.pid}-#{Thread.current.object_id}.yml")
end
|
#storage_used ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fluoride-collector/storage/fs.rb', line 21
def storage_used
dir = Dir.new(directory)
dir.inject(0) do |sum, file|
if file =~ %r{\A\.}
sum
else
sum + File.size(File::join(directory, file))
end
end
end
|
#write ⇒ Object
15
16
17
18
19
|
# File 'lib/fluoride-collector/storage/fs.rb', line 15
def write
storage_file do |file|
file.write(record_yaml)
end
end
|