Module: Filebase::Drivers::Mixin

Included in:
JSON, Marshal, YAML
Defined in:
lib/filebase/drivers/mixin.rb

Instance Method Summary collapse

Instance Method Details

#countObject



28
29
30
# File 'lib/filebase/drivers/mixin.rb', line 28

def count
  Dir["#{@root}/*.#{@extension}"].size
end

#delete(key) ⇒ Object



32
33
34
# File 'lib/filebase/drivers/mixin.rb', line 32

def delete( key )
	::FileUtils.remove( path( key ) )
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/filebase/drivers/mixin.rb', line 20

def has_key?( key )
  File.exist?( path(key) )
end

#initialize(root) ⇒ Object



6
7
8
9
# File 'lib/filebase/drivers/mixin.rb', line 6

def initialize(root)
  @root = root.to_s
  FileUtils.mkdir_p(root) unless File.exist?(root)
end

#keysObject



24
25
26
# File 'lib/filebase/drivers/mixin.rb', line 24

def keys
  Dir["#{@root}/*.#{@extension}"].sort.map { |fname| File.basename(fname, ".#{@extension}") }
end

#path(key) ⇒ Object

Raises:



15
16
17
18
# File 'lib/filebase/drivers/mixin.rb', line 15

def path( key )
  raise Filebase::Error, "can't generate a path using a nil key" unless key
  "#{@root}/#{key}.#{@extension}"
end

#rootObject



11
12
13
# File 'lib/filebase/drivers/mixin.rb', line 11

def root
  @root
end