Class: Picky::Backends::Memory::Basic

Inherits:
Object
  • Object
show all
Includes:
Helpers::File
Defined in:
lib/picky/backends/memory/basic.rb

Overview

Base class for all memory-based index files.

Provides necessary helper methods for its subclasses. Not directly useable, as it does not provide dump/load methods.

Direct Known Subclasses

JSON, Marshal

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::File

#create_directory

Constructor Details

#initialize(cache_file_path, hash_type = Hash, options = {}) ⇒ Basic

An index cache takes a path, without file extension, which will be provided by the subclasses.



29
30
31
32
33
34
# File 'lib/picky/backends/memory/basic.rb', line 29

def initialize cache_file_path, hash_type = Hash, options = {}
  @cache_file_path = cache_file_path
  @hash_type       = hash_type
  @empty           = options[:empty]
  @initial         = options[:initial]
end

Instance Attribute Details

#cache_file_pathObject (readonly)

This file’s cache file without extensions.



20
21
22
# File 'lib/picky/backends/memory/basic.rb', line 20

def cache_file_path
  @cache_file_path
end

#hash_typeObject (readonly)

What hash type to use. Default: ::Hash



24
25
26
# File 'lib/picky/backends/memory/basic.rb', line 24

def hash_type
  @hash_type
end

Instance Method Details

#cache_pathObject



44
45
46
# File 'lib/picky/backends/memory/basic.rb', line 44

def cache_path
  [cache_file_path, type, extension].join(?.)
end

#deleteObject

Deletes the file.



63
64
65
# File 'lib/picky/backends/memory/basic.rb', line 63

def delete
  `rm -Rf #{cache_path}`
end

#emptyObject

The empty index that is used for putting the index together before it is dumped into the files.



51
52
53
# File 'lib/picky/backends/memory/basic.rb', line 51

def empty
  @empty && @empty.clone || hash_type.new
end

#extensionObject

The default extension for index files is “index”.



38
39
40
# File 'lib/picky/backends/memory/basic.rb', line 38

def extension
  :index
end

#initialObject

The initial content before loading from file/indexing.



57
58
59
# File 'lib/picky/backends/memory/basic.rb', line 57

def initial
  @initial && @initial.clone || hash_type.new
end

#to_sObject



69
70
71
# File 'lib/picky/backends/memory/basic.rb', line 69

def to_s
  "#{self.class}(#{cache_path})"
end

#typeObject



41
42
43
# File 'lib/picky/backends/memory/basic.rb', line 41

def type
  :memory
end