<commit_before># == Schema Information
#
# Table name: taggings
#
#  id            :integer          not null, primary key
#  taggable_type :string(255)
#  taggable_id   :integer
#  created_by    :integer
#  created_at    :datetime
#  updated_at    :datetime
#  tag_id        :integer
#

class TaggingsController < ApplicationController

  # FIXME: Refactor and re-enable cop
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  #
  def create
    klass = params[:taggable_type].constantize
    obj = klass.find(params[:taggable_id])
    res = false
    if obj.respond_to?(:tag_list) && !params[:tag].blank?
      tag = params[:tag]
      # if we want owned tags. Not sure we do...
      # res = current_user.tag(obj,with: params[:tagging][:name])
      unless obj.tag_list.include?(tag)
        obj.tag_list.add(tag)
        res = obj.save
        found_tag = klass.tag_counts.find_by(name: tag)<commit_msg>safer than constantizing<commit_after># == Schema Information
#
# Table name: taggings
#
#  id            :integer          not null, primary key
#  taggable_type :string(255)
#  taggable_id   :integer
#  created_by    :integer
#  created_at    :datetime
#  updated_at    :datetime
#  tag_id        :integer
#

class TaggingsController < ApplicationController

  TAGGABLE_TYPES = {
    'Person'    => Person,
    'V2::Event' => V2::Event
  }.freeze

  # FIXME: Refactor and re-enable cop
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  #
  def create
    klass = TAGGABLE_TYPES.fetch(params[:taggable_type])
    res = false
    if klass && params[:tag].present?
      obj = klass.find(params[:taggable_id])
      tag = params[:tag]
      # if we want owned tags. Not sure we do...
      # res = current_user.tag(obj,with: params[:tagging][:name])
      unless obj.tag_list.include?(tag)
        obj.tag_list.add(tag)
        res = obj.save
        found_tag = klass.tag_counts.find_by(name: tag)
{'fraction_non_alphanumeric': 0.11394380853277836, 'fraction_numerical': 0.004162330905306972, 'mean_word_length': 2.900608519269777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4137065', 'n_tokens_mistral': 654, 'n_tokens_neox': 655, 'n_words': 143}