<commit_before>require 'rails'
require 'mongoff/model'
require 'mongoff/record'
require 'mongoff/criteria'
require 'rails_admin/lib/mongoff_model_config'
require 'rails_admin/lib/mongoff_property'
require 'rails_admin/lib/mongoff_association'

module RailsAdmin
  class MongoffAbstractModel < AbstractModel

    include RailsAdmin::Adapters::Mongoid

    def initialize(mongoff_model)
      @model = mongoff_model
      @model_name = mongoff_model.to_s
    end

    def model
      @model
    end

    def config
      @config ||= RailsAdmin::MongoffModelConfig.new(self)
    end

    def scoped
      model.all
    end

    def associations
      @associations ||= model.associations.values.collect { |association| RailsAdmin::MongoffAssociation.new(association, model) }
    end

    def embedded_in?(abstract_model = nil)
      abstract_model.nil? ||
        begin
          @embeddors ||= Set.new
          @not_embeddors ||= Set.new
          if @embeddors.include?(abstract_model)
            true
          elsif @not_embeddors.include?(abstract_model)
            false
          elsif abstract_model.model.properties.any? do |property|
            abstract_model.model.property_model(property).eql?(model) &&
              ((referenced = abstract_model.model.property_schema(property)['referenced']).nil? || !referenced)
          end
            @embeddors << abstract_model
            true
          else
            @not_embeddors << abstract_model
            false
          end
        end
    end

    def properties
      unless @properties
        @properties = []
        model.properties.each do |property|
          unless model.property_model?(property)
            @properties << RailsAdmin::MongoffProperty.new(property, model)
          end
        end
      end
      @properties
    end

    class << self

      def new(m)
        unless mongoff_abstract_models = Thread.current[:mongoff_abstract_models]
          Thread.current[:mongoff_abstract_models] = mongoff_abstract_models = {}
        end
        mongoff_abstract_models[m.to_s] ||= old_new(m)
      end

      def abstract_model_for(mongoff_entity)
        if mongoff_entity.is_a?(RailsAdmin::MongoffAbstractModel)
          mongoff_entity
        else
          mongoff_entity = mongoff_entity.orm_model if mongoff_entity.is_a?(Mongoff::Record)
          new(mongoff_entity)
        end
      end
    end
  end
end

module Mongoff
  class Model

    def model_name
      @model_name ||= ActiveModel::Name.new(nil, nil, data_type.name)
    end

    def human_attribute_name(attribute, options = {})
      attribute.to_s.titleize
    end

    def method_defined?(*args)
      property?(args[0])
    end

    def relations
      associations
    end

    def reflect_on_association(name)
      relations[name.to_sym]
    end

  end

  class Record
    def safe_send(key)
      self[key]
    end

    def class
      orm_model
    end

    def associations
      self.class.associations
    end
  end

  class Criteria

    include Kaminari::ConfigurationMethods::ClassMethods
    include Kaminari::MongoidCriteriaMethods
    include Kaminari::PageScopeMethods
<commit_msg>Compatibility with recent version of Action View<commit_after>require 'rails'
require 'mongoff/model'
require 'mongoff/record'
require 'mongoff/criteria'
require 'rails_admin/lib/mongoff_model_config'
require 'rails_admin/lib/mongoff_property'
require 'rails_admin/lib/mongoff_association'

module RailsAdmin
  class MongoffAbstractModel < AbstractModel

    include RailsAdmin::Adapters::Mongoid

    def initialize(mongoff_model)
      @model = mongoff_model
      @model_name = mongoff_model.to_s
    end

    def model
      @model
    end

    def config
      @config ||= RailsAdmin::MongoffModelConfig.new(self)
    end

    def scoped
      model.all
    end

    def associations
      @associations ||= model.associations.values.collect { |association| RailsAdmin::MongoffAssociation.new(association, model) }
    end

    def embedded_in?(abstract_model = nil)
      abstract_model.nil? ||
        begin
          @embeddors ||= Set.new
          @not_embeddors ||= Set.new
          if @embeddors.include?(abstract_model)
            true
          elsif @not_embeddors.include?(abstract_model)
            false
          elsif abstract_model.model.properties.any? do |property|
            abstract_model.model.property_model(property).eql?(model) &&
              ((referenced = abstract_model.model.property_schema(property)['referenced']).nil? || !referenced)
          end
            @embeddors << abstract_model
            true
          else
            @not_embeddors << abstract_model
            false
          end
        end
    end

    def properties
      unless @properties
        @properties = []
        model.properties.each do |property|
          unless model.property_model?(property)
            @properties << RailsAdmin::MongoffProperty.new(property, model)
          end
        end
      end
      @properties
    end

    class << self

      def new(m)
        unless mongoff_abstract_models = Thread.current[:mongoff_abstract_models]
          Thread.current[:mongoff_abstract_models] = mongoff_abstract_models = {}
        end
        mongoff_abstract_models[m.to_s] ||= old_new(m)
      end

      def abstract_model_for(mongoff_entity)
        if mongoff_entity.is_a?(RailsAdmin::MongoffAbstractModel)
          mongoff_entity
        else
          mongoff_entity = mongoff_entity.orm_model if mongoff_entity.is_a?(Mongoff::Record)
          new(mongoff_entity)
        end
      end
    end
  end
end

module Mongoff
  class Model

    def model_name
      @model_name ||= ActiveModel::Name.new(nil, nil, data_type.name)
    end

    def human_attribute_name(attribute, options = {})
      attribute.to_s.titleize
    end

    def method_defined?(*args)
      property?(args[0])
    end

    def relations
      associations
    end

    def reflect_on_association(name)
      relations[name.to_sym]
    end

    def to_key
      nil
    end

  end

  class Record
    def safe_send(key)
      self[key]
    end

    def class
      orm_model
    end

    def associations
      self.class.associations
    end

    def to_model
      orm_model
    end
  end

  class Criteria

    include Kaminari::ConfigurationMethods::ClassMethods
    include Kaminari::MongoidCriteriaMethods
    include Kaminari::PageScopeMethods

{'fraction_non_alphanumeric': 0.07712641890841238, 'fraction_numerical': 0.00031099362463069506, 'mean_word_length': 2.448793565683646, 'pattern_counts': {'":': 0, '<': 21, '<?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': '5207845', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1875, 'n_words': 378}