Class: Tilt::Fs::FileSystem::Dir
- Inherits:
-
Object
- Object
- Tilt::Fs::FileSystem::Dir
- Defined in:
- lib/tilt/fs/file_system/dir.rb
Instance Attribute Summary collapse
-
#data_path ⇒ Object
readonly
Returns the value of attribute data_path.
-
#flag_no_data ⇒ Object
readonly
Returns the value of attribute flag_no_data.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#real_path ⇒ Object
readonly
Returns the value of attribute real_path.
Instance Method Summary collapse
- #attr ⇒ Object
- #create_file_or_dir(path) ⇒ Object
- #find(path) ⇒ Object
- #glob_and_create(glob_path) ⇒ Object
-
#initialize(new_real_path, new_data_path) ⇒ Dir
constructor
A new instance of Dir.
- #is_dir? ⇒ Boolean
- #is_file? ⇒ Boolean
- #search(token) ⇒ Object
- #stat ⇒ Object
Constructor Details
#initialize(new_real_path, new_data_path) ⇒ Dir
Returns a new instance of Dir.
11 12 13 14 15 16 17 |
# File 'lib/tilt/fs/file_system/dir.rb', line 11 def initialize(new_real_path, new_data_path) @logger = FS_LOGGER @real_path = new_real_path @name = ::Pathname.new(real_path).basename.to_s @data_path = new_data_path logger.debug "dir#new(): created, real_path = #{real_path}" end |
Instance Attribute Details
#data_path ⇒ Object (readonly)
Returns the value of attribute data_path.
8 9 10 |
# File 'lib/tilt/fs/file_system/dir.rb', line 8 def data_path @data_path end |
#flag_no_data ⇒ Object (readonly)
Returns the value of attribute flag_no_data.
9 10 11 |
# File 'lib/tilt/fs/file_system/dir.rb', line 9 def flag_no_data @flag_no_data end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/tilt/fs/file_system/dir.rb', line 6 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/tilt/fs/file_system/dir.rb', line 5 def name @name end |
#real_path ⇒ Object (readonly)
Returns the value of attribute real_path.
7 8 9 |
# File 'lib/tilt/fs/file_system/dir.rb', line 7 def real_path @real_path end |
Instance Method Details
#attr ⇒ Object
37 38 39 |
# File 'lib/tilt/fs/file_system/dir.rb', line 37 def attr ::RFuse::Stat.directory FS_DEFAULT_DIR_MODE, stat end |
#create_file_or_dir(path) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/tilt/fs/file_system/dir.rb', line 41 def create_file_or_dir(path) logger.debug "dir#create_file_or_dir(): path = #{path}" if ::FileTest.directory?(path) Dir.new path, data_path else File.new path, data_path end end |
#find(path) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tilt/fs/file_system/dir.rb', line 63 def find(path) logger.debug "dir#find(): path = #{path}" lookup_path = ::File.join(real_path, path) if ::FileTest.file?(lookup_path) create_file_or_dir lookup_path elsif ::FileTest.directory?(lookup_path) create_file_or_dir lookup_path else logger.debug "dir#find(): find template for #{path}" templates = ::Dir.glob(::File.join real_path, "#{path}*") if templates.length === 1 logger.debug "dir#find(): found in #{templates.first}" create_file_or_dir templates.first else raise ::Errno::ENOENT.new(path) end end end |
#glob_and_create(glob_path) ⇒ Object
50 51 52 53 54 |
# File 'lib/tilt/fs/file_system/dir.rb', line 50 def glob_and_create(glob_path) ::Dir.glob(glob_path).map do |found_path| create_file_or_dir found_path end end |
#is_dir? ⇒ Boolean
19 20 21 |
# File 'lib/tilt/fs/file_system/dir.rb', line 19 def is_dir? true end |
#is_file? ⇒ Boolean
23 24 25 |
# File 'lib/tilt/fs/file_system/dir.rb', line 23 def is_file? false end |
#search(token) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/tilt/fs/file_system/dir.rb', line 56 def search(token) logger.debug "dir#search(): token = #{token}" glob_path = ::File.join(real_path, "#{token}*") logger.debug "dir#search(): glob_path = #{glob_path}" glob_and_create glob_path end |
#stat ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/tilt/fs/file_system/dir.rb', line 27 def stat { :uid => ::Process.uid, :gid => ::Process.gid, :atime => ::Time.now, :mtime => ::Time.now, :size => 0, } end |