Module: Filebase::Drivers::Mixin
Instance Method Summary collapse
- #count ⇒ Object
- #delete(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
- #initialize(root) ⇒ Object
- #keys ⇒ Object
- #path(key) ⇒ Object
- #root ⇒ Object
Instance Method Details
#count ⇒ Object
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
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 |
#keys ⇒ Object
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
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 |
#root ⇒ Object
11 12 13 |
# File 'lib/filebase/drivers/mixin.rb', line 11 def root @root end |