<commit_before>module Rectify
  class Presenter
    include Virtus.model

    def for_controller(controller)
      @controller = controller
    end

    def method_missing(method_name, *args, &block)
      if view_context.respond_to?(method_name)
        view_context.public_send(method_name, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      view_context.respond_to?(method_name, include_private)
    end

    private

    attr_reader :controller

    def view_context
      controller && controller.view_context
    end
  end
end<commit_msg>Cache view_context as Rails creates a new one on each call<commit_after>module Rectify
  class Presenter
    include Virtus.model

    def for_controller(controller)
      @controller = controller
    end

    def method_missing(method_name, *args, &block)
      if view_context.respond_to?(method_name)
        view_context.public_send(method_name, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      view_context.respond_to?(method_name, include_private)
    end

    private

    attr_reader :controller

    def view_context
      @view_context ||= begin
        controller && controller.view_context
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06142322097378277, 'fraction_numerical': 0.0, 'mean_word_length': 2.964391691394659, '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': '3915889', 'n_tokens_mistral': 396, 'n_tokens_neox': 386, 'n_words': 94}