Class: Bookbinder::FileSystem::Directory
- Inherits:
-
Object
- Object
- Bookbinder::FileSystem::Directory
- Defined in:
- lib/bookbinder/file_system/directory.rb
Instance Method Summary collapse
- #each ⇒ Object
- #exists?(path) ⇒ Boolean
- #get_file(path, mode = 'r', &blk) ⇒ Object
- #get_io(path, &blk) ⇒ Object
-
#initialize(path) ⇒ Directory
constructor
A new instance of Directory.
- #read(path) ⇒ Object
- #set_file(path, file) ⇒ Object
- #write(path, data) ⇒ Object
Constructor Details
#initialize(path) ⇒ Directory
Returns a new instance of Directory.
3 4 5 |
# File 'lib/bookbinder/file_system/directory.rb', line 3 def initialize(path) @dir = path end |
Instance Method Details
#each ⇒ Object
47 48 49 50 51 52 |
# File 'lib/bookbinder/file_system/directory.rb', line 47 def each Dir.glob(File.join(@dir, '**', '*')) { |path| next if File.directory?(path) yield(path.sub(/#{@dir}\//, '')) } end |
#exists?(path) ⇒ Boolean
8 9 10 |
# File 'lib/bookbinder/file_system/directory.rb', line 8 def exists?(path) File.exists?(full_path(path)) end |
#get_file(path, mode = 'r', &blk) ⇒ Object
33 34 35 36 37 |
# File 'lib/bookbinder/file_system/directory.rb', line 33 def get_file(path, mode = 'r', &blk) fpath = full_path(path) must_exist(fpath) if mode[0] != 'w' File.open(fpath, mode, &blk) end |
#get_io(path, &blk) ⇒ Object
28 29 30 |
# File 'lib/bookbinder/file_system/directory.rb', line 28 def get_io(path, &blk) get_file(path, 'r', &blk) end |
#read(path) ⇒ Object
13 14 15 16 17 |
# File 'lib/bookbinder/file_system/directory.rb', line 13 def read(path) fpath = full_path(path) must_exist(fpath) File.read(fpath) end |
#set_file(path, file) ⇒ Object
40 41 42 43 44 |
# File 'lib/bookbinder/file_system/directory.rb', line 40 def set_file(path, file) fpath = full_path(path) FileUtils.mkdir_p(File.dirname(fpath)) FileUtils.cp(file.path, fpath) end |