<commit_before># frozen_string_literal: true

module GobiertoCommon
  class ContextService
    attr_reader :context

    delegate :present?, to: :resource

    def initialize(context)
      @context = fill_missing_parts(context.to_s.strip)
    end

    def resource
      @resource ||= begin
                      GlobalID::Locator.locate @context
                    rescue ActiveRecord::RecordNotFound
                      nil
                    end
    end

    private

    def fill_missing_parts(context)
      return context if context =~ %r{^gid://gobierto//}

      missing_part = "gid://"
      missing_part += "gobierto/" unless context =~ %r{^gobierto/}<commit_msg>Fix prefix expression of global ids<commit_after># frozen_string_literal: true

module GobiertoCommon
  class ContextService
    attr_reader :context

    delegate :present?, to: :resource

    def initialize(context)
      @context = fill_missing_parts(context.to_s.strip)
    end

    def resource
      @resource ||= begin
                      GlobalID::Locator.locate @context
                    rescue ActiveRecord::RecordNotFound
                      nil
                    end
    end

    private

    def fill_missing_parts(context)
      return context if context =~ %r{^gid://gobierto/}

      missing_part = "gid://"
      missing_part += "gobierto/" unless context =~ %r{^gobierto/}
{'fraction_non_alphanumeric': 0.08641975308641975, 'fraction_numerical': 0.0, 'mean_word_length': 2.167816091954023, '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': '3130252', 'n_tokens_mistral': 392, 'n_tokens_neox': 368, 'n_words': 92}