Class: CC::Analyzer::MountedPath

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

Constant Summary collapse

DEFAULT_CODECLIMATE_TMP =
"/tmp/cc".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_prefix, container_prefix, path = nil) ⇒ MountedPath

Returns a new instance of MountedPath.



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

def initialize(host_prefix, container_prefix, path = nil)
  @host_prefix = host_prefix
  @container_prefix = container_prefix
  @path = path
end

Class Method Details

.codeObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cc/analyzer/mounted_path.rb', line 6

def self.code
  host_prefix = ENV["CODECLIMATE_CODE"]
  host_prefix ||= ENV["CODE_PATH"] # deprecated

  if ENV["CODECLIMATE_DOCKER"]
    new(host_prefix, "/code")
  else
    host_prefix ||= Dir.pwd

    new(host_prefix, host_prefix)
  end
end

.tmpObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/cc/analyzer/mounted_path.rb', line 19

def self.tmp
  host_prefix = ENV["CODECLIMATE_TMP"]
  host_prefix ||= DEFAULT_CODECLIMATE_TMP

  if ENV["CODECLIMATE_DOCKER"]
    new(host_prefix, "/tmp/cc")
  else
    new(host_prefix, host_prefix)
  end
end

Instance Method Details

#container_pathObject



44
45
46
47
48
49
50
# File 'lib/cc/analyzer/mounted_path.rb', line 44

def container_path
  if path
    File.join(container_prefix, path)
  else
    container_prefix
  end
end

#deleteObject



71
72
73
# File 'lib/cc/analyzer/mounted_path.rb', line 71

def delete
  File.delete(container_path)
end

#file?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/cc/analyzer/mounted_path.rb', line 58

def file?
  File.file?(container_path)
end

#host_pathObject



36
37
38
39
40
41
42
# File 'lib/cc/analyzer/mounted_path.rb', line 36

def host_path
  if path
    File.join(host_prefix, path)
  else
    host_prefix
  end
end

#join(path) ⇒ Object



52
53
54
55
56
# File 'lib/cc/analyzer/mounted_path.rb', line 52

def join(path)
  @path = path

  self
end

#readObject



62
63
64
# File 'lib/cc/analyzer/mounted_path.rb', line 62

def read
  File.read(container_path)
end

#write(content) ⇒ Object



66
67
68
69
# File 'lib/cc/analyzer/mounted_path.rb', line 66

def write(content)
  FileUtils.mkdir_p(File.dirname(container_path))
  File.write(container_path, content)
end