<commit_before># TODO require

module Kernel

  def callable_from_handler handler
    case handler
    when String
      -> { handler }
    when Symbol
      method handler
    else
      handler
    end
  end

end

class Object

  def not_nil?
    not self.nil?
  end

  def presense default = nil, &block
    if present? 
      block_given? ? yield(self) : self
    else
      default
    end
  end

end


class Array

  def extract_options_by_keys! *keys
    options = self.extract_options!
    options.extract! keys if keys
    self.push options
    options
  end

end


module ActiveModel
  module MassAssignmentSecurity

    module ClassMethods

      def remove_attr_accessible *args
        options = args.extract_options!
        role = options[:as] || :default
        source_role = options[:source_as] || role

        attr_accessible *(accessible_attributes(source_role).to_a - args), role: role
      end

      def add_attr_accessible *args
        options = args.extract_options!
        role = options[:as] || :default
        source_role = options[:source_as] || :default

        attr_accessible *(accessible_attributes(source_role).to_a + args), role: role
      end

    end

  end
end


# FIXME
module ActionMailer
  class Base

    def self.email_with_name email, name
      "#{name} <#{email}>".html_safe
    end

  end
end


module ActionView
  class Renderer

    alias_method :render_original, :render
    def render(context, options)
      if options.key?(:partial)
        err = nil
        Array.wrap(options[:partial]).each do |partial|
          begin
            return render_original(context, options.merge({:partial => partial}))
          rescue ActionView::MissingTemplate => e
            err = e
          end
        end
        raise err # FIXME Не работает
      else
        return render_template(context, options)
      end
    end

  end
end


module ActionView
  class PartialRenderer

    def setup_with_wrapper_option(context, options, block)
      # TODO При тако походе prefix префиксует к имени каталога, а не файла (необходимо модифицировать to_partial_path)
      # TODO postfix, prefix могут быть Array[String]

      res = setup_without_wrapper_option(context, options, block)
      return res unless @path

      # prefix = options.delete(:prefix) || options[:locals].try(:delete, :prefix)
      postfix = options.delete(:postfix) || options[:locals].try(:delete, :postfix)
      # @path = "#{prefix}_#{@path}" if prefix
      @path = "#{@path}_#{postfix}" if postfix

      res
    end

    alias_method_chain :setup, :wrapper_option

  end
end


module BreadcrumbsOnRails
  module ActionController

    def add_breadcrumbs(breadcrumbs)
      breadcrumbs.each { |breadcrumb| add_breadcrumb(breadcrumb) }
    end

  end
end


module ActiveRecord
  class Base

    def model_class
      self.class
    end

  end
end
<commit_msg>Поменял способ патчинга `postfix` для `render`. Теперь опция `partial` метода `render` может быть `Proc` (вызывается с аргументом - объект).<commit_after># TODO require

module Kernel

  def callable_from_handler handler
    case handler
    when String
      -> { handler }
    when Symbol
      method handler
    else
      handler
    end
  end

end

class Object

  def not_nil?
    not self.nil?
  end

  def presense default = nil, &block
    if present? 
      block_given? ? yield(self) : self
    else
      default
    end
  end

end


class Array

  def extract_options_by_keys! *keys
    options = self.extract_options!
    options.extract! keys if keys
    self.push options
    options
  end

end


module ActiveModel
  module MassAssignmentSecurity

    module ClassMethods

      def remove_attr_accessible *args
        options = args.extract_options!
        role = options[:as] || :default
        source_role = options[:source_as] || role

        attr_accessible *(accessible_attributes(source_role).to_a - args), role: role
      end

      def add_attr_accessible *args
        options = args.extract_options!
        role = options[:as] || :default
        source_role = options[:source_as] || :default

        attr_accessible *(accessible_attributes(source_role).to_a + args), role: role
      end

    end

  end
end


# FIXME
module ActionMailer
  class Base

    def self.email_with_name email, name
      "#{name} <#{email}>".html_safe
    end

  end
end


module ActionView
  class Renderer

    alias_method :render_original, :render
    def render(context, options)
      if options.key?(:partial)
        err = nil
        Array.wrap(options[:partial]).each do |partial|
          begin
            return render_original(context, options.merge({:partial => partial}))
          rescue ActionView::MissingTemplate => e
            err = e
          end
        end
        raise err # FIXME Не работает
      else
        return render_template(context, options)
      end
    end

  end
end


module ActionView
  class PartialRenderer

    def setup(context, options, block)
      @view   = context
      partial = options[:partial]
      postfix = options[:postfix] ? Array.wrap(postfix).join('_') : nil

      @options = options
      @locals  = options[:locals] || {}
      @block   = block
      @details = extract_details(options)

      if String === partial
        @object     = options[:object]
        @path       = partial
        @collection = collection
      else
        @object = partial

        if @collection = collection_from_object || collection
          paths = @collection_data = @collection.map { |o| Proc === partial ? partial(@object) : partial_path(o) }
          @path = paths.uniq.size == 1 ? paths.first : nil
        else
          @path = Proc === partial ? partial(@object) : partial_path
        end
      end

      if @path
        @variable, @variable_counter = retrieve_variable(postfix ? "#{@path}_#{postfix}" : @path)
      else
        paths.map! { |path| retrieve_variable(path).unshift(postfix ? "#{path}_#{postfix}" : path) }
      end

      if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/
        raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " +
                                "make sure your partial name starts with a letter or underscore, " +
                                "and is followed by any combinations of letters, numbers, or underscores.")
      end

      extract_format(@path, @details)
      self
    end

  end

end


module BreadcrumbsOnRails
  module ActionController

    def add_breadcrumbs(breadcrumbs)
      breadcrumbs.each { |breadcrumb| add_breadcrumb(breadcrumb) }
    end

  end
end


module ActiveRecord
  class Base

    def model_class
      self.class
    end

  end
end

{'fraction_non_alphanumeric': 0.0844965844965845, 'fraction_numerical': 0.0004455004455004455, 'mean_word_length': 2.437978560490046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5013101', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1980, 'n_words': 559}