<commit_before>require 'fulmar/domain/service/configuration_service'
require 'colorize'

module Fulmar
  module Domain
    module Service
      module Helper
        # Provides the helper methods used in the tasks
        module CommonHelper
          attr_accessor :environment

          def full_configuration
            configuration.configuration
          end

          def configuration
            (@_config_service ||= Fulmar::Domain::Service::ConfigurationService.instance)
          end

          def composer(command, arguments = Fulmar::Infrastructure::Service::ComposerService::DEFAULT_PARAMS)
            (storage['composer'] ||= Fulmar::Infrastructure::Service::ComposerService.new(local_shell)).execute(command, arguments)
          end

          def local_shell
            storage['local_shell'] ||= new_shell(configuration[:local_path])
          end

          def remote_shell
            storage['remote_shell'] ||= new_shell(configuration[:remote_path], configuration.ssh_user_and_host)
          end

          def file_sync
            storage['file_sync'] ||= Fulmar::FileSync.create_transfer configuration
          end

          def render_templates
            (Fulmar::Domain::Service::ConfigRenderingService.new configuration).render
          end

          def git
            storage['git'] ||= Fulmar::Infrastructure::Service::GitService.new configuration
          end

          def upload(filename)
            Fulmar::Infrastructure::Service::CopyService.upload(local_shell, filename, configuration.ssh_user_and_host, configuration[:remote_path])
          end

          def download(filename)
            Fulmar::Infrastructure::Service::CopyService.download(local_shell, configuration.ssh_user_and_host, filename, configuration[:local_path])
          end

          def new_shell(path, hostname = 'localhost')
            shell = Fulmar::Infrastructure::Service::ShellService.new(path, hostname)
            shell.strict = true
            shell.debug = configuration[:debug]
            shell
          end

          def storage
            fail 'You need to set an environment and a target first' unless configuration.ready?
            @storage ||= {}
            @storage[configuration.environment] ||= {}
            @storage[configuration.environment][configuration.target] ||= {}
          end

          def info(text)
            puts (ENV['TERM'] == 'xterm-256color' ? text.blue : "* Info: #{text}") if verbose
          end

          def warn(text)
            STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.magenta : "* Warning: #{text}")
          end

          def error(text)
            STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.light_red : "* Error: #{text}")<commit_msg>[REFACTORING] Rename warning to be consistent with the two other methods<commit_after>require 'fulmar/domain/service/configuration_service'
require 'colorize'

module Fulmar
  module Domain
    module Service
      module Helper
        # Provides the helper methods used in the tasks
        module CommonHelper
          attr_accessor :environment

          def full_configuration
            configuration.configuration
          end

          def configuration
            (@_config_service ||= Fulmar::Domain::Service::ConfigurationService.instance)
          end

          def composer(command, arguments = Fulmar::Infrastructure::Service::ComposerService::DEFAULT_PARAMS)
            (storage['composer'] ||= Fulmar::Infrastructure::Service::ComposerService.new(local_shell)).execute(command, arguments)
          end

          def local_shell
            storage['local_shell'] ||= new_shell(configuration[:local_path])
          end

          def remote_shell
            storage['remote_shell'] ||= new_shell(configuration[:remote_path], configuration.ssh_user_and_host)
          end

          def file_sync
            storage['file_sync'] ||= Fulmar::FileSync.create_transfer configuration
          end

          def render_templates
            (Fulmar::Domain::Service::ConfigRenderingService.new configuration).render
          end

          def git
            storage['git'] ||= Fulmar::Infrastructure::Service::GitService.new configuration
          end

          def upload(filename)
            Fulmar::Infrastructure::Service::CopyService.upload(local_shell, filename, configuration.ssh_user_and_host, configuration[:remote_path])
          end

          def download(filename)
            Fulmar::Infrastructure::Service::CopyService.download(local_shell, configuration.ssh_user_and_host, filename, configuration[:local_path])
          end

          def new_shell(path, hostname = 'localhost')
            shell = Fulmar::Infrastructure::Service::ShellService.new(path, hostname)
            shell.strict = true
            shell.debug = configuration[:debug]
            shell
          end

          def storage
            fail 'You need to set an environment and a target first' unless configuration.ready?
            @storage ||= {}
            @storage[configuration.environment] ||= {}
            @storage[configuration.environment][configuration.target] ||= {}
          end

          def info(text)
            puts (ENV['TERM'] == 'xterm-256color' ? text.blue : "* Info: #{text}") if verbose
          end

          def warning(text)
            STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.magenta : "* Warning: #{text}")
          end

          def error(text)
            STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.light_red : "* Error: #{text}")
{'fraction_non_alphanumeric': 0.10157932519741565, 'fraction_numerical': 0.003230437903804738, 'mean_word_length': 2.463642013673089, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884140', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1367, 'n_words': 295}