Class: FluidFeatures::Persistence::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/fluidfeatures/persistence/storage.rb

Direct Known Subclasses

Buckets, Features

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger = nil) ⇒ Storage

Returns a new instance of Storage.



8
9
10
11
12
13
# File 'lib/fluidfeatures/persistence/storage.rb', line 8

def initialize(config, logger=nil)
  @dir = config["dir"]
  @logger = logger || Logger.new(STDERR)
  @file_name = "#{self.class.to_s.split('::').last.downcase}.pstore"
  FileUtils.mkpath(dir) unless Dir.exists?(dir)
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



6
7
8
# File 'lib/fluidfeatures/persistence/storage.rb', line 6

def dir
  @dir
end

#file_nameObject

Returns the value of attribute file_name.



6
7
8
# File 'lib/fluidfeatures/persistence/storage.rb', line 6

def file_name
  @file_name
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/fluidfeatures/persistence/storage.rb', line 6

def logger
  @logger
end

#storeObject

Returns the value of attribute store.



6
7
8
# File 'lib/fluidfeatures/persistence/storage.rb', line 6

def store
  @store
end

Instance Method Details

#file_sizeObject



23
24
25
26
# File 'lib/fluidfeatures/persistence/storage.rb', line 23

def file_size
  # TODO: rescue should return nil here
  File.size(path) rescue 0
end

#pathObject



19
20
21
# File 'lib/fluidfeatures/persistence/storage.rb', line 19

def path
  File.join(dir, file_name)
end