<commit_before>module LightService
  module Outcomes
    SUCCESS = 0
    FAILURE = 1
  end

  class Context < Hash
    attr_accessor :outcome, :message, :error_code, :current_action

    def initialize(context={}, outcome=::LightService::Outcomes::SUCCESS, message='', error_code=nil)
      @outcome, @message, @error_code = outcome, message, error_code
      @skip_all = false
      context.to_hash.each {|k,v| self[k] = v}
      self
    end

    def self.make(context={})
      unless context.is_a? Hash or context.is_a? ::LightService::Context
        raise ArgumentError, 'Argument must be Hash or LightService::Context'
      end

      return context if context.is_a?(Context)
      self.new(context)
    end

    def add_to_context(values)
      self.merge! values
    end

    def success?
      @outcome == ::LightService::Outcomes::SUCCESS
    end

    def failure?
      success? == false
    end

    def skip_all?
      @skip_all
    end

    def set_success!(message)
      warn '`set_success!` is DEPRECATED: please use `succeed!` instead'
      succeed!(message)
    end

    def succeed!(message=nil)
      @message = message
      @outcome = ::LightService::Outcomes::SUCCESS
    end

    def set_failure!(message)
      warn '`set_failure!` is DEPRECATED: please use `fail!` instead'
      fail!(message)
    end

    def fail!(message=nil, error_code=nil)
      @message = message
      @error_code = error_code
      @outcome = ::LightService::Outcomes::FAILURE
    end

    def fail_with_rollback!(message=nil, error_code=nil)
      fail!(message, error_code)
      raise FailWithRollbackError.new
    end

    def skip_all!(message=nil)
      @message = message
      @skip_all = true
    end

    def stop_processing?<commit_msg>Use localizer when passing/failing the context<commit_after>module LightService
  module Outcomes
    SUCCESS = 0
    FAILURE = 1
  end

  class Context < Hash
    attr_accessor :outcome, :message, :error_code, :current_action

    def initialize(context={}, outcome=::LightService::Outcomes::SUCCESS, message='', error_code=nil)
      @outcome, @message, @error_code = outcome, message, error_code
      @skip_all = false
      context.to_hash.each {|k,v| self[k] = v}
      self
    end

    def self.make(context={})
      unless context.is_a? Hash or context.is_a? ::LightService::Context
        raise ArgumentError, 'Argument must be Hash or LightService::Context'
      end

      return context if context.is_a?(Context)
      self.new(context)
    end

    def add_to_context(values)
      self.merge! values
    end

    def success?
      @outcome == ::LightService::Outcomes::SUCCESS
    end

    def failure?
      success? == false
    end

    def skip_all?
      @skip_all
    end

    def set_success!(message)
      warn '`set_success!` is DEPRECATED: please use `succeed!` instead'
      succeed!(message)
    end

    def succeed!(message=nil)
      @message = Configuration.localizer.success(message, current_action)
      @outcome = ::LightService::Outcomes::SUCCESS
    end

    def set_failure!(message)
      warn '`set_failure!` is DEPRECATED: please use `fail!` instead'
      fail!(message)
    end

    def fail!(message=nil, error_code=nil)
      @message = Configuration.localizer.failure(message, current_action)
      @error_code = error_code
      @outcome = ::LightService::Outcomes::FAILURE
    end

    def fail_with_rollback!(message=nil, error_code=nil)
      fail!(message, error_code)
      raise FailWithRollbackError.new
    end

    def skip_all!(message=nil)
      @message = message
      @skip_all = true
    end

    def stop_processing?
{'fraction_non_alphanumeric': 0.1019510854630393, 'fraction_numerical': 0.0010992030777686177, 'mean_word_length': 2.986856516976999, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4484541', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1109, 'n_words': 278}