<commit_before>require 'construi/container'

require 'colorize'
require 'docker'

module Construi

  class Image
    private_class_method :new

    def initialize(image)
      @image = image.refresh!
    end

    def id
      @image.id
    end

    def delete
      @image.delete
    end

    def docker_image
      @image
    end

    def tagged?
      @image.info['RepoTags'] != '<none>:<none>'
    end

    def insert_local(file)
      puts "\nCopying #{file.host} to #{file.container}...".green

      img = IntermediateImage.seed(self)

      img.map do |i|
        Image.wrap i.docker_image
          .insert_local 'localPath' => file.host, 'outputPath' => file.container
      end

      if file.permissions
        chmod = "chmod -R #{file.permissions} #{file.container}"

        puts " > #{chmod}"
        img = img.run chmod
      end

      img.run "ls -l #{file.container}"

      img.image
    end

    def insert_locals(files)
      IntermediateImage.seed(self).reduce(files) { |i, f| i.insert_local f }.image
    end

    def run(cmd, env = [])
      Container.run(self, cmd, env)
    end

    def ==(other)
      other.is_a? Image and id == other.id
    end

    def self.from(config)
      image = create(config.image) unless config.image.nil?<commit_msg>Fixes for code climate issues<commit_after>require 'construi/container'

require 'colorize'
require 'docker'

module Construi

  class Image
    private_class_method :new

    def initialize(image)
      @image = image.refresh!
    end

    def id
      @image.id
    end

    def delete
      @image.delete
    end

    def docker_image
      @image
    end

    def tagged?
      @image.info['RepoTags'] != '<none>:<none>'
    end

    def insert_local(file)
      puts "\nCopying #{file.host} to #{file.container}...".green

      img = IntermediateImage.seed(self)

      img.map do |i|
        Image.wrap i.docker_image
          .insert_local 'localPath' => file.host, 'outputPath' => file.container
      end

      img.map { |i| i.chmod file.container, file.permissions } if file.permissions

      img.run "ls -l #{file.container}"

      img.image
    end

    def insert_locals(files)
      IntermediateImage.seed(self).reduce(files) { |i, f| i.insert_local f }.image
    end

    def chmod(file, permissions)
        chmod = "chmod -R #{permissions} #{file}"

        puts " > #{chmod}"
        run chmod
    end

    def run(cmd, env = [])
      Container.run(self, cmd, env)
    end

    def ==(other)
      other.is_a? Image and id == other.id
    end

    def self.from(config)
      image = create(config.image) unless config.image.nil?
{'fraction_non_alphanumeric': 0.11805026656511805, 'fraction_numerical': 0.0, 'mean_word_length': 2.215422276621787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4972144', 'n_tokens_mistral': 885, 'n_tokens_neox': 847, 'n_words': 216}