Class: CFBundle::Storage::FileSystem
- Defined in:
- lib/cfbundle/storage/file_system.rb
Overview
A bundle storage that reads from the file system.
Instance Method Summary collapse
-
#directory?(path) ⇒ Boolean
Returns whether a given directory exists within the storage.
-
#exist?(path) ⇒ Boolean
Returns whether a given path exists within the storage.
-
#file?(path) ⇒ Boolean
Returns whether a given file exists within the storage.
-
#foreach(path) ⇒ Enumerator
Returns an enumerator that enumerates the files contained in a directory.
-
#initialize(path) ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#open(path) {|file| ... } ⇒ Object, IO
Opens a file for reading in the storage.
Methods inherited from Base
Constructor Details
#initialize(path) ⇒ FileSystem
Returns a new instance of FileSystem.
9 10 11 |
# File 'lib/cfbundle/storage/file_system.rb', line 9 def initialize(path) @root = path end |
Instance Method Details
#directory?(path) ⇒ Boolean
Returns whether a given directory exists within the storage.
25 26 27 28 |
# File 'lib/cfbundle/storage/file_system.rb', line 25 def directory?(path) entry = find(path) !entry.nil? && File.directory?(entry) end |
#exist?(path) ⇒ Boolean
Returns whether a given path exists within the storage.
14 15 16 |
# File 'lib/cfbundle/storage/file_system.rb', line 14 def exist?(path) find(path) != nil end |
#file?(path) ⇒ Boolean
Returns whether a given file exists within the storage.
19 20 21 22 |
# File 'lib/cfbundle/storage/file_system.rb', line 19 def file?(path) entry = find(path) !entry.nil? && File.file?(entry) end |
#foreach(path) ⇒ Enumerator
Returns an enumerator that enumerates the files contained in a directory.
36 37 38 39 40 41 42 43 44 |
# File 'lib/cfbundle/storage/file_system.rb', line 36 def foreach(path) Enumerator.new do |y| base = Dir.entries(find!(path)).sort.each loop do entry = base.next y << PathUtils.join(path, entry) unless ['.', '..'].include?(entry) end end end |
#open(path) {|file| ... } ⇒ Object, IO
Opens a file for reading in the storage.
31 32 33 |
# File 'lib/cfbundle/storage/file_system.rb', line 31 def open(path, &block) File.open find!(path), &block end |