Class: Fluoride::Collector::Storage::FS

Inherits:
Fluoride::Collector::Storage show all
Defined in:
lib/fluoride-collector/storage/fs.rb

Instance Attribute Summary

Attributes inherited from Fluoride::Collector::Storage

#collection_type, #record

Instance Method Summary collapse

Methods inherited from Fluoride::Collector::Storage

#initialize, #record_yaml, #thread_locals

Constructor Details

This class inherits a constructor from Fluoride::Collector::Storage

Instance Method Details

#directoryObject



7
8
9
# File 'lib/fluoride-collector/storage/fs.rb', line 7

def directory
  @config.directory
end

#storage_fileObject



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_limitObject



11
12
13
# File 'lib/fluoride-collector/storage/fs.rb', line 11

def storage_limit
  @config.storage_limit
end

#storage_pathObject



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_usedObject



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

#writeObject



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