<commit_before># -*- encoding : utf-8 -*-
module RailsAdmin
  module Config
    module Actions
      class Toggle < Base
        RailsAdmin::Config::Actions.register(self)

        # Is the action acting on the root level (Example: /admin/contact)
        register_instance_option :root? do
          false
        end

        register_instance_option :collection? do
          false
        end

        # Is the action on an object scope (Example: /admin/team/1/edit)
        register_instance_option :member? do
          true
        end

        register_instance_option :controller do
          proc do
            ajax_link = Proc.new do |fv, on, badge|
              render json: {
                text: fv.html_safe,
                href: toggle_path(model_name: @abstract_model, id: @object.id, method: @meth, on: on.to_s),
                class: 'label ' + badge,
              }
            end
            if params['id'].present?
              begin
                @object = @abstract_model.model.unscoped.find(params['id'])
                @meth = params[:method]
                @object.send(@meth + '=', params[:on] == '1' ? true : false)
                if @object.save
                  if params['ajax'].present?
                    if params[:on] == '1'
                      ajax_link.call('✓', 0, 'label-success')
                    else
                      ajax_link.call('✘', 1, 'label-danger')
                    end
                  else
                    if params[:on] == '1'
                      flash[:success] = I18n.t('admin.toggle.enabled', attr: @meth)
                    else
                      flash[:success] = I18n.t('admin.toggle.disabled', attr: @meth)
                    end
                  end
                else
                  if params['ajax'].present?
                    render text: @object.errors.full_messages.join(', '), layout: false, status: 422
                  else<commit_msg>Lock the object before modifying it<commit_after># -*- encoding : utf-8 -*-
module RailsAdmin
  module Config
    module Actions
      class Toggle < Base
        RailsAdmin::Config::Actions.register(self)

        # Is the action acting on the root level (Example: /admin/contact)
        register_instance_option :root? do
          false
        end

        register_instance_option :collection? do
          false
        end

        # Is the action on an object scope (Example: /admin/team/1/edit)
        register_instance_option :member? do
          true
        end

        register_instance_option :controller do
          proc do
            ajax_link = Proc.new do |fv, on, badge|
              render json: {
                text: fv.html_safe,
                href: toggle_path(model_name: @abstract_model, id: @object.id, method: @meth, on: on.to_s),
                class: 'label ' + badge,
              }
            end
            if params['id'].present?
              begin
                @object = @abstract_model.model.unscoped.lock.find(params['id'])
                @meth = params[:method]
                @object.send(@meth + '=', params[:on] == '1' ? true : false)
                if @object.save
                  if params['ajax'].present?
                    if params[:on] == '1'
                      ajax_link.call('✓', 0, 'label-success')
                    else
                      ajax_link.call('✘', 1, 'label-danger')
                    end
                  else
                    if params[:on] == '1'
                      flash[:success] = I18n.t('admin.toggle.enabled', attr: @meth)
                    else
                      flash[:success] = I18n.t('admin.toggle.disabled', attr: @meth)
                    end
                  end
                else
                  if params['ajax'].present?
                    render text: @object.errors.full_messages.join(', '), layout: false, status: 422
                  else
{'fraction_non_alphanumeric': 0.10591821183642368, 'fraction_numerical': 0.007112014224028448, 'mean_word_length': 1.315108759553204, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5814283', 'n_tokens_mistral': 1091, 'n_tokens_neox': 991, 'n_words': 260}