Class: CC::Analyzer::Filesystem
- Inherits:
-
Object
- Object
- CC::Analyzer::Filesystem
- Defined in:
- lib/cc/analyzer/filesystem.rb
Instance Method Summary collapse
- #all ⇒ Object
- #any?(&block) ⇒ Boolean
- #exist?(path) ⇒ Boolean
- #file_paths ⇒ Object
- #files_matching(globs) ⇒ Object
-
#initialize(root) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #path_for(path) ⇒ Object
- #read_path(path) ⇒ Object
- #source_buffer_for(path) ⇒ Object
Constructor Details
#initialize(root) ⇒ Filesystem
Returns a new instance of Filesystem.
5 6 7 |
# File 'lib/cc/analyzer/filesystem.rb', line 5 def initialize(root) @root = root end |
Instance Method Details
#all ⇒ Object
27 28 29 |
# File 'lib/cc/analyzer/filesystem.rb', line 27 def all @files ||= Dir.chdir(@root) { Dir.glob("**/*") } end |
#any?(&block) ⇒ Boolean
31 32 33 |
# File 'lib/cc/analyzer/filesystem.rb', line 31 def any?(&block) all.any?(&block) end |
#exist?(path) ⇒ Boolean
9 10 11 |
# File 'lib/cc/analyzer/filesystem.rb', line 9 def exist?(path) File.exist?(path_for(path)) end |
#file_paths ⇒ Object
21 22 23 24 25 |
# File 'lib/cc/analyzer/filesystem.rb', line 21 def file_paths Dir.chdir(@root) do Dir["**/*.*"].select { |path| File.file?(path) }.sort end end |
#files_matching(globs) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cc/analyzer/filesystem.rb', line 35 def files_matching(globs) Dir.chdir(@root) do globs.map do |glob| Dir.glob(glob) end.flatten.sort.uniq end end |
#path_for(path) ⇒ Object
43 44 45 |
# File 'lib/cc/analyzer/filesystem.rb', line 43 def path_for(path) File.join(@root, path) end |
#read_path(path) ⇒ Object
17 18 19 |
# File 'lib/cc/analyzer/filesystem.rb', line 17 def read_path(path) File.read(path_for(path)) end |
#source_buffer_for(path) ⇒ Object
13 14 15 |
# File 'lib/cc/analyzer/filesystem.rb', line 13 def source_buffer_for(path) SourceBuffer.new(path, read_path(path)) end |