<commit_before>module Railgun
  class Resource
    module Associations

      attr_accessor :associations

      def initialize(*args)
        super
        prepare_associations
      end

      def association(key, type, options={})
        existing = associations.find{|a|a.key == key}
        if existing
          existing.update(type, options)
        else
          associations << Association.new(key, type, options)
        end
      end

      def association_for(attribute)
        associations.find{|a| a.foreign_key == attribute.key }
      end

    protected
      
      def prepare_associations
        @associations = []
        if ActiveRecord::Base.connection.table_exists? resource_class.table_name
          reflections = resource_class.reflect_on_all_associations
          reflections.each do |reflection|
            next if reflection.options[:polymorphic]
            key = reflection.name
            type = reflection.macro
            options = {
              :klass => reflection.klass,
              :foreign_key => reflection.association_foreign_key
            }
            @associations << Association.new(key, type, options)
          end
        end
      end
      
    end
  end
  
  class Association
    
    attr_accessor :key, :type, :options
    
    def initialize(key, type, options={})
      @key = key.to_sym
      @type = type.to_sym
      @options = {}
      parse_options(options)
    end

    def klass
      @options[:klass] || @options[:class_name].try(:classify).try(:constantize) || @key.classify.constantize
    end
<commit_msg>Don't process has_and_belongs_to_many associations<commit_after>module Railgun
  class Resource
    module Associations

      attr_accessor :associations

      def initialize(*args)
        super
        prepare_associations
      end

      def association(key, type, options={})
        existing = associations.find{|a|a.key == key}
        if existing
          existing.update(type, options)
        else
          associations << Association.new(key, type, options)
        end
      end

      def association_for(attribute)
        associations.find{|a| a.foreign_key == attribute.key }
      end

    protected
      
      def prepare_associations
        @associations = []
        if ActiveRecord::Base.connection.table_exists? resource_class.table_name
          reflections = resource_class.reflect_on_all_associations
          reflections.each do |reflection|
            next if reflection.macro == :has_and_belongs_to_many || reflection.options[:polymorphic]
            key = reflection.name
            type = reflection.macro
            options = {
              :klass => reflection.klass,
              :foreign_key => reflection.association_foreign_key
            }
            @associations << Association.new(key, type, options)
          end
        end
      end
      
    end
  end
  
  class Association
    
    attr_accessor :key, :type, :options
    
    def initialize(key, type, options={})
      @key = key.to_sym
      @type = type.to_sym
      @options = {}
      parse_options(options)
    end

    def klass
      @options[:klass] || @options[:class_name].try(:classify).try(:constantize) || @key.classify.constantize
    end

{'fraction_non_alphanumeric': 0.08509984639016897, 'fraction_numerical': 0.0, 'mean_word_length': 2.0804162724692525, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2474947', 'n_tokens_mistral': 892, 'n_tokens_neox': 875, 'n_words': 191}