<commit_before>require 'specinfra/version'
require 'specinfra/backend'
require 'specinfra/command'
require 'specinfra/command_result'
require 'specinfra/configuration'
require 'specinfra/runner'
 
require 'specinfra/helper/detect_os'
require 'specinfra/helper/os'
require 'specinfra/helper/backend'
require 'specinfra/helper/docker'
require 'specinfra/helper/lxc'
require 'specinfra/helper/configuration'
require 'specinfra/helper/properties'
require 'specinfra/helper/set'
 
# TODO: move to specinfra
require 'net/scp'
 
module Lightchef
  def self.backend=(backend)
    @backend = backend
  end

  def self.backend
    @backend
  end

  def self.create_local_backend
    create_backend(:exec)
  end

  def self.create_ssh_backend(options)
    Specinfra.configuration.request_pty = true

    Specinfra.configuration.host = options.delete(:host)
    Specinfra.configuration.ssh_options = options

    Specinfra.configuration.ssh = Net::SSH.start(
      Specinfra.configuration.host,
      Specinfra.configuration.ssh_options[:user],
      Specinfra.configuration.ssh_options
    )

    # TODO: move to specinfra
    Specinfra.configuration.scp =
      Net::SCP.new(Specinfra.configuration.ssh)

    create_backend(:ssh)
  end

  private
  def self.create_backend(type)
    type = type.to_s.capitalize

    obj = Object.new
    obj.extend(::Specinfra::Helper.const_get(type))
    obj.backend.tap do |b|
      Lightchef.backend = b
    end
  end

  module SpecinfraHelpers
    module RunCommand
      def backend
        Lightchef.backend
      end
 
      def run_command(cmd)
        backend.run_command(cmd)
      end
    end
  end
end
 
Specinfra::Helper::Os.class_eval { remove_method(:run_command) }
 
module Specinfra
  class << self
    def configuration
      Specinfra::Configuration
    end
 
    def command
      Specinfra::Command::Base.new
    end
  end
 
  module Helper
    class DetectOs
      extend Specinfra::Helper::Os
      extend Lightchef::SpecinfraHelpers::RunCommand
    end
  end
 
  module Backend
    class Base
      include Specinfra::Helper::Os
      include Specinfra::Helper::Properties
      include Specinfra::Helper::Configuration
    end
  end
  module Command
    class Base
      include Specinfra::Helper::Os
      include Specinfra::Helper::Properties
      include Lightchef::SpecinfraHelpers::RunCommand
    end
 
    class Processor
      def self.backend
        $backend
      end
    end
  end
end
 
class Class
  def subclasses
    result = []
    ObjectSpace.each_object(Class) do |k|
      result << k if k < self
    end
    result
  end
end
 
class String
  def to_snake_case
    self.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
  end
 
  def to_camel_case
    return self if self !~ /_/ && self =~ /[A-Z]+.*/
    split('_').map{|e| e.capitalize}.join
  end
end
 
class Runner
  def backend
    obj = Object.new
    obj.extend(Specinfra::Helper::Exec)
    obj.backend.tap do |b|
      Lightchef::Specinfra.backend = b
    end
  end
end<commit_msg>Fix according to specinfra 2.0.0beta18<commit_after>require 'specinfra'
 
# TODO: move to specinfra
 
module Lightchef
  def self.backend=(backend)
    @backend = backend
  end

  def self.backend
    @backend
  end

  def self.create_local_backend
    create_backend(:exec)
  end

  def self.create_ssh_backend(options)
    Specinfra.configuration.request_pty = true

    Specinfra.configuration.host = options.delete(:host)
    Specinfra.configuration.ssh_options = options
    create_backend(:ssh)
  end

  private
  def self.create_backend(type)
    Specinfra.configuration.backend = type
    Lightchef.backend = Specinfra.backend
  end

  module SpecinfraHelpers
    module RunCommand
      def backend
        Lightchef.backend
      end

      def run_command(cmd)
        backend.run_command(cmd)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09678243105209397, 'fraction_numerical': 0.0022982635342185904, 'mean_word_length': 2.988798370672098, 'pattern_counts': {'":': 0, '<': 8, '<?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': '7527002', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1220, 'n_words': 268}