<commit_before>module EasySerializer
  Cacher = Struct.new(:serializer) do
    include Helpers

    def self.call(serializer, options, value, &block)
      cacher = Cacher.new(serializer)
      cacher.set(options: options, block: block, value: value)
      cacher.execute
    end

    def self.root_call(serializer, options, value, &block)
      cacher = Cacher.new(serializer)
      options[:cache_key] = options[:key]
      options[:root_call] = true
      cacher.set(options: options, block: block, value: value)
      cacher.execute
    end

    attr_accessor :object, :options, :block
    attr_writer :value

    delegate :object, to: :serializer

    def set(options)
      options.each { |k, v| send("#{k}=", v) }
    end

    def value
      return unless object && block
      @value ||= serializer.instance_exec object, &block
    end


    def key
      @key ||= if options[:cache_key]
                 option_to_value(options[:cache_key], value, serializer)
               elsif options[:serializer] || options[:root_call]
                 [value, 'EasySerialized'].flatten
               else
                 [value, options[:name], 'EasySerialized'].flatten
               end
    end

    def execute<commit_msg>Avoid duplication in the call methods<commit_after>module EasySerializer
  Cacher = Struct.new(:serializer) do
    include Helpers

    def self.call(serializer, options, value, &block)
      cacher = Cacher.new(serializer)
      cacher.set(options: options, block: block, value: value)
      cacher.execute
    end

    def self.root_call(serializer, options, value, &block)
      options[:cache_key] = options[:key]
      options[:root_call] = true
      call(serializer, options, value, &block)
    end

    attr_accessor :object, :options, :block
    attr_writer :value

    delegate :object, to: :serializer

    def set(options)
      options.each { |k, v| send("#{k}=", v) }
    end

    def value
      return unless object && block
      @value ||= serializer.instance_exec object, &block
    end


    def key
      @key ||= if options[:cache_key]
                 option_to_value(options[:cache_key], value, serializer)
               elsif options[:serializer] || options[:root_call]
                 [value, 'EasySerialized'].flatten
               else
                 [value, options[:name], 'EasySerialized'].flatten
               end
    end

    def execute
{'fraction_non_alphanumeric': 0.1076923076923077, 'fraction_numerical': 0.0, 'mean_word_length': 2.4819102749638207, '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': '944133', 'n_tokens_mistral': 716, 'n_tokens_neox': 694, 'n_words': 181}