Sha256: 784a9d292441159b31df507ce70df70849618eba9ab30ac8d76f27e70d12a29d

Contents?: true

Size: 1.57 KB

Versions: 181

Compression:

Stored size: 1.57 KB

Contents

module CC
  module Analyzer
    class MountedPath
      DEFAULT_CODECLIMATE_TMP = "/tmp/cc".freeze

      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

      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

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

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

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

      def join(path)
        @path = path

        self
      end

      def file?
        File.file?(container_path)
      end

      def read
        File.read(container_path)
      end

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

      def delete
        File.delete(container_path)
      end

      private

      attr_reader :host_prefix, :container_prefix, :path
    end
  end
end

Version data entries

181 entries across 181 versions & 2 rubygems

Version Path
codeclimate-0.96.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.95.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.94.1 lib/cc/analyzer/mounted_path.rb
codeclimate-0.94.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.93.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.92.1 lib/cc/analyzer/mounted_path.rb
codeclimate-0.92.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.91.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.90.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.89.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.88.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.5 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.4 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.3 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.2 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.1 lib/cc/analyzer/mounted_path.rb
codeclimate-0.87.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.86.0 lib/cc/analyzer/mounted_path.rb
codeclimate-0.85.29 lib/cc/analyzer/mounted_path.rb
codeclimate-0.85.28 lib/cc/analyzer/mounted_path.rb