<commit_before>module Simpre
  module Helper
    def decorate(item_or_collection)
      if item_or_collection.respond_to?(:map)
        item_or_collection.map { |item| decorate(item) }
      else
        item = item_or_collection
        decorator = "#{item.class}Presenter".constantize
        return item if decorator === item
        decorator.new(item, self)
      end
    end
  end
end<commit_msg>Get the view_context when called from a rails controller<commit_after>module Simpre
  module Helper
    def decorate(item_or_collection)
      if item_or_collection.respond_to?(:map)
        item_or_collection.map { |item| decorate(item) }
      else
        item = item_or_collection
        decorator = "#{item.class}Presenter".constantize
        return item if decorator === item
        decorator.new(item, self)
        decorator.new(item, current_view_context)
      end
    end

    private

    def current_view_context
      is_a?(ApplicationController) ? view_context : self
    end
  end
end
{'fraction_non_alphanumeric': 0.07462686567164178, 'fraction_numerical': 0.0, 'mean_word_length': 2.8544061302681993, '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': '768842', 'n_tokens_mistral': 302, 'n_tokens_neox': 299, 'n_words': 70}