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.



4
5
6
# File 'lib/cc/analyzer/filesystem.rb', line 4

def initialize(root)
  @root = root
end

Instance Method Details

#any?(&block) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#files_matching(globs) ⇒ Object



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

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



16
17
18
# File 'lib/cc/analyzer/filesystem.rb', line 16

def read_path(path)
  File.read(path_for(path))
end

#source_buffer_for(path) ⇒ Object



12
13
14
# File 'lib/cc/analyzer/filesystem.rb', line 12

def source_buffer_for(path)
  SourceBuffer.new(path, read_path(path))
end

#write_path(path, content) ⇒ Object



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

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