Class: Cardigan::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/cardigan/directory.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Directory

Returns a new instance of Directory.



6
7
8
# File 'lib/cardigan/directory.rb', line 6

def initialize path
  @path = File.expand_path(path)
end

Instance Method Details

#createObject



26
27
28
# File 'lib/cardigan/directory.rb', line 26

def create
  FileUtils.mkdir_p @path
end

#delete(file) ⇒ Object



22
23
24
# File 'lib/cardigan/directory.rb', line 22

def delete file
  FileUtils.rm File.join(@path, file)
end

#find(pattern) ⇒ Object



30
31
32
# File 'lib/cardigan/directory.rb', line 30

def find pattern
  Dir.glob(File.join(@path, pattern)).map {|path| YAML::load File.read(path) }
end

#has_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/cardigan/directory.rb', line 10

def has_file? file
  File.exist? File.join(@path, file)
end

#load(file) ⇒ Object



14
15
16
# File 'lib/cardigan/directory.rb', line 14

def load file
  YAML::load File.read(File.join(@path, file))
end

#store(file, hash) ⇒ Object



18
19
20
# File 'lib/cardigan/directory.rb', line 18

def store file, hash
  File.open(File.join(@path, file), 'w') {|f| f.print hash.to_yaml}
end