<commit_before># frozen_string_literal: true
require 'yaml'
require 'docker'
require 'httparty'

# Plugin class will represent an individual plugin.
# It will check the metadata of the type of plugins to make decisions.
# It's two main functions are to:
#  1. Load the configuration of the specific plugin and load anything needed for that type.
#  2. Execute the command properly based on the type
class Plugin
  # TODO: likely this type of numberic enum is not the right route and symbols should be used.
  # however I like the idea of the list being bound by possibilities.
  module TypeEnum
    SCRIPT = 1
    CONTAINER = 2
    API = 4
  end

  def initialize(file)
    @name = File.basename(file, ".*")
    @config = YAML.load_file(file)
    @lang_settings = lang_settings
    @container = nil
    load
  end


  # TODO: use name or label to match up with the config name
  # Setup plugin by type
  def load
    case @config['plugin']['type']
    when 'script'
      filename = "#{@name}#{@lang_settings[:file_type]}"
      File.open("scripts/#{filename}", 'w') do |file|
        file.write(@config[:plugin][:write])
      end
      File.chmod(0777, "scripts/#{filename}")
      _image = Docker::Image.create(fromImage: @lang_settings[:image])
      config_hash = {
        name: @name,
        Image: @lang_settings[:image],
        HostConfig: {
          Binds: ["#{Dir.pwd}/scripts/#{filename}:/scripts/#{filename}"]
        },
        Cmd: ["bash", "/scripts/#{filename}"],
        Entrypoint: "/scripts/#{filename}",
        Tty: true<commit_msg>fix nil reference<commit_after># frozen_string_literal: true
require 'yaml'
require 'docker'
require 'httparty'

# Plugin class will represent an individual plugin.
# It will check the metadata of the type of plugins to make decisions.
# It's two main functions are to:
#  1. Load the configuration of the specific plugin and load anything needed for that type.
#  2. Execute the command properly based on the type
class Plugin
  # TODO: likely this type of numberic enum is not the right route and symbols should be used.
  # however I like the idea of the list being bound by possibilities.
  module TypeEnum
    SCRIPT = 1
    CONTAINER = 2
    API = 4
  end

  def initialize(file)
    @name = File.basename(file, ".*")
    @config = YAML.load_file(file)
    @lang_settings = lang_settings
    @container = nil
    load
  end


  # TODO: use name or label to match up with the config name
  # Setup plugin by type
  def load
    case @config['plugin']['type']
    when 'script'
      filename = "#{@name}#{@lang_settings[:file_type]}"
      File.open("scripts/#{filename}", 'w') do |file|
        file.write(@config['plugin']['write'])
      end
      File.chmod(0777, "scripts/#{filename}")
      _image = Docker::Image.create(fromImage: @lang_settings[:image])
      config_hash = {
        name: @name,
        Image: @lang_settings[:image],
        HostConfig: {
          Binds: ["#{Dir.pwd}/scripts/#{filename}:/scripts/#{filename}"]
        },
        Cmd: ["bash", "/scripts/#{filename}"],
        Entrypoint: "/scripts/#{filename}",
        Tty: true
{'fraction_non_alphanumeric': 0.11858974358974358, 'fraction_numerical': 0.0057692307692307696, 'mean_word_length': 3.0691003911342896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3701286', 'n_tokens_mistral': 950, 'n_tokens_neox': 911, 'n_words': 323}