<commit_before>require 'bricks'
require 'active_record'

module Bricks
  module Adapters
    module ActiveRecord
      def association?(name)
        @class.reflect_on_association(name.to_sym)
      end

      def association(name)
        @class.reflect_on_association(name.to_sym)
      end

      Bricks::Builder.send(:include, self)
    end
  end
end<commit_msg>Support all kinds of associations in ActiveRecord adapter.<commit_after>require 'bricks'
require 'active_record'

module Bricks
  module Adapters
    module ActiveRecord
      class Association
        attr_reader :type

        def initialize(klass, kind)
          @class = klass
          @type  = case kind
                   when :belongs_to;                         :one
                   when :has_many, :has_and_belongs_to_many; :many
                   else "Unknown AR association type: #{kind}."
                   end
        end

        def klass
          @class
        end
      end

      def association?(name, type = nil)
        association(name, type)
      end

      def association(name, type = nil)
        ar = @class.reflect_on_association(name.to_sym)
        a  = Association.new(ar.klass, ar.macro)

        a if type.nil? || a.type == type
      end

      Bricks::Builder.send(:include, self)
    end
  end
end
{'fraction_non_alphanumeric': 0.07633587786259542, 'fraction_numerical': 0.0, 'mean_word_length': 1.9328859060402686, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4135091', 'n_tokens_mistral': 381, 'n_tokens_neox': 371, 'n_words': 98}