Class: Chitin::FSObject
- Includes:
- Enumerable
- Defined in:
- lib/chitin/file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#search ⇒ Object
Returns the value of attribute search.
Instance Method Summary collapse
- #directory? ⇒ Boolean
- #each(&block) ⇒ Object
- #files ⇒ Object
-
#initialize(path, opts = {}) ⇒ FSObject
constructor
The choice to not have File.expand_path here is explicitly done.
- #lstat ⇒ Object
- #size ⇒ Object
- #symlink? ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
- #unknown_type? ⇒ Boolean
Constructor Details
#initialize(path, opts = {}) ⇒ FSObject
The choice to not have File.expand_path here is explicitly done. Relativity is up to the user. Also it got really annoying seeing the same prefix over and over and over again on lists of files.
12 13 14 15 16 |
# File 'lib/chitin/file.rb', line 12 def initialize(path, opts={}) @path = path @search = proc { path } @unknown = opts[:unknown] end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/chitin/file.rb', line 5 def path @path end |
#search ⇒ Object
Returns the value of attribute search.
6 7 8 |
# File 'lib/chitin/file.rb', line 6 def search @search end |
Instance Method Details
#directory? ⇒ Boolean
65 66 67 |
# File 'lib/chitin/file.rb', line 65 def directory? false end |
#each(&block) ⇒ Object
41 42 43 |
# File 'lib/chitin/file.rb', line 41 def each(&block) files.values.each &block end |
#files ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chitin/file.rb', line 22 def files return @files if @files files = Dir[search.call] @files = files.inject({}) do |h, f| f = f[2..-1] if f.start_with? './' h[f] = if File.directory? f D f elsif File.file? f F f elsif File.symlink? f S f else FSObject.new f, :unknown => true end h end end |
#lstat ⇒ Object
53 54 55 |
# File 'lib/chitin/file.rb', line 53 def lstat File.lstat @path end |
#size ⇒ Object
49 50 51 |
# File 'lib/chitin/file.rb', line 49 def size files.size end |
#symlink? ⇒ Boolean
61 62 63 |
# File 'lib/chitin/file.rb', line 61 def symlink? false end |
#to_a ⇒ Object
45 46 47 |
# File 'lib/chitin/file.rb', line 45 def to_a files.values end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/chitin/file.rb', line 57 def to_s path end |
#unknown_type? ⇒ Boolean
18 19 20 |
# File 'lib/chitin/file.rb', line 18 def unknown_type? @unknown end |