<commit_before>module Forms
  class TranslatorSelector
    include Mongoid::Document

    field :translator_type, type: Symbol
    field :bulk_source, type: Boolean
    belongs_to :data_type, class_name: Setup::DataType.to_s, inverse_of: nil
    belongs_to :translator, class_name: Setup::Translator.to_s, inverse_of: nil

    after_initialize do
      unless translator.present?
        data_type_criteria =
            case translator_type
              when :Export, :Conversion
                :source_data_type
              when :Import, :Update
                :target_data_type
            end

        if data_type_criteria
          self.translator = Setup::Translator.all.any_in(data_type_criteria => [nil, data_type]).and(type: translator_type).first
        else
          self.translator = Setup::Translator.all(type: translator_type).first
        end
      end
    end

    validates_presence_of :translator_type, :translator
    validate do |selector|
      if selector.translator && selector.translator_type
        errors.add(:translator, "must be of type #{selector.translator_type}") unless selector.translator.type == selector.translator_type
      end
    end

    rails_admin do
      visible false
      edit do
        field :translator
        # do
        #   associated_collection_scope do
        #     data_type = bindings[:object].try(:data_type)
        #     bulk_source = bindings[:object].try(:bulk_source)
        #     data_type_criteria =
        #         case translator_type = bindings[:object].try(:translator_type)
        #           when :Export, :Conversion
        #             :source_data_type
        #           when :Import, :Update
        #             :target_data_type
        #         end
        #     Proc.new { |scope|
        #       scope =
        #           if data_type_criteria
        #             scope.any_in(data_type_criteria => [nil, data_type]).and(type: translator_type)
        #           else
        #             scope.all(type: translator_type)
        #           end
        #       if translator_type == :Export && bulk_source
        #         scope = scope.and(bulk_source: true)
        #       end
        #       scope
        #     }
        #   end
        # end
      end
    end
  end
end<commit_msg>Update translator export<commit_after>module Forms
  class TranslatorSelector
    include Mongoid::Document

    field :translator_type, type: Symbol
    field :bulk_source, type: Boolean
    belongs_to :data_type, class_name: Setup::DataType.to_s, inverse_of: nil
    belongs_to :translator, class_name: Setup::Translator.to_s, inverse_of: nil

    after_initialize do
      unless translator.present?
        data_type_criteria =
            case translator_type
              when :Export, :Conversion
                :source_data_type
              when :Import, :Update
                :target_data_type
            end

        if data_type_criteria
          self.translator = Setup::Translator.all.any_in(data_type_criteria => [nil, data_type]).and(type: translator_type).first
        else
          self.translator = Setup::Translator.all(type: translator_type).first
        end
      end
    end

    validates_presence_of :translator_type, :translator
    validate do |selector|
      if selector.translator && selector.translator_type
        errors.add(:translator, "must be of type #{selector.translator_type}") unless selector.translator.type == selector.translator_type
      end
    end

    rails_admin do
      visible false
      edit do
        field :translator do
          associated_collection_scope do
            data_type = bindings[:object].try(:data_type)
            bulk_source = bindings[:object].try(:bulk_source)
            data_type_criteria =
                case translator_type = bindings[:object].try(:translator_type)
                  when :Export, :Conversion
                    :source_data_type
                  when :Import, :Update
                    :target_data_type
                end
            Proc.new { |scope|
              scope =
                  if data_type_criteria
                    scope.any_in(data_type_criteria => [nil, data_type]).and(type: translator_type)
                  else
                    scope.all(type: translator_type)
                  end
              if translator_type == :Export && bulk_source
                scope = scope.and(bulk_source: true)
              end
              scope
            }
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.074114800967671, 'fraction_numerical': 0.0, 'mean_word_length': 1.8248447204968945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6187405', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1224, 'n_words': 265}