<commit_before>module Spree
  module Api
    module V1
      class TaxonsController < Spree::Api::BaseController
        def index
          if taxonomy
            @taxons = taxonomy.root.children
          else
            if params[:ids]
              @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
            else
              @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
            end
          end

          @taxons = @taxons.page(params[:page]).per(params[:per_page])
          respond_with(@taxons)
        end

        def show
          @taxon = taxon
          respond_with(@taxon)
        end

        def jstree
          show
        end

        def new
        end

        def create
          authorize! :create, Taxon
          @taxon = Spree::Taxon.new(taxon_params)
          @taxon.taxonomy_id = params[:taxonomy_id]
          taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])

          if taxonomy.nil?
            @taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
            invalid_resource!(@taxon) and return
          end

          @taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
<commit_msg>Fixes ActiveModel::Errors#[]= is deprecated warning message in Rails 5<commit_after>module Spree
  module Api
    module V1
      class TaxonsController < Spree::Api::BaseController
        def index
          if taxonomy
            @taxons = taxonomy.root.children
          else
            if params[:ids]
              @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
            else
              @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
            end
          end

          @taxons = @taxons.page(params[:page]).per(params[:per_page])
          respond_with(@taxons)
        end

        def show
          @taxon = taxon
          respond_with(@taxon)
        end

        def jstree
          show
        end

        def new
        end

        def create
          authorize! :create, Taxon
          @taxon = Spree::Taxon.new(taxon_params)
          @taxon.taxonomy_id = params[:taxonomy_id]
          taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])

          if taxonomy.nil?
            @taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
            invalid_resource!(@taxon) and return
          end

          @taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]

{'fraction_non_alphanumeric': 0.10957408081543502, 'fraction_numerical': 0.0025482344375682563, 'mean_word_length': 2.046563192904656, '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': '6982461', 'n_tokens_mistral': 837, 'n_tokens_neox': 813, 'n_words': 150}