class CC::Analyzer::MountedPath

Constants

DEFAULT_CODECLIMATE_TMP

Attributes

container_prefix[R]
host_prefix[R]
path[R]

Public Class Methods

code() click to toggle source
# 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
new(host_prefix, container_prefix, path = nil) click to toggle source
# 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
tmp() click to toggle source
# 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

Public Instance Methods

container_path() click to toggle source
# File lib/cc/analyzer/mounted_path.rb, line 44
def container_path
  if path
    File.join(container_prefix, path)
  else
    container_prefix
  end
end
delete() click to toggle source
# File lib/cc/analyzer/mounted_path.rb, line 71
def delete
  File.delete(container_path)
end
file?() click to toggle source
# File lib/cc/analyzer/mounted_path.rb, line 58
def file?
  File.file?(container_path)
end
host_path() click to toggle source
# 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) click to toggle source
# File lib/cc/analyzer/mounted_path.rb, line 52
def join(path)
  @path = path

  self
end
read() click to toggle source
# File lib/cc/analyzer/mounted_path.rb, line 62
def read
  File.read(container_path)
end
write(content) click to toggle source
# 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