Class: CC::Analyzer::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/analyzer/filesystem.rb

Instance Method Summary collapse

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

#any?(&block) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cc/analyzer/filesystem.rb', line 26

def any?(&block)
  file_paths.any?(&block)
end

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/cc/analyzer/filesystem.rb', line 9

def exist?(path)
  File.exist?(path_for(path))
end

#files_matching(globs) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/cc/analyzer/filesystem.rb', line 30

def files_matching(globs)
  Dir.chdir(@root) do
    globs.map do |glob|
      Dir.glob(glob)
    end.flatten.sort.uniq
  end
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

#write_path(path, content) ⇒ Object



21
22
23
24
# File 'lib/cc/analyzer/filesystem.rb', line 21

def write_path(path, content)
  File.write(path_for(path), content)
  File.chown(root_uid, root_gid, path_for(path))
end