<commit_before>require 'active_record'
require 'set'

# Groups and members
module Groupify
  module ActiveRecord
    extend ActiveSupport::Concern
    
    included do
      # Define a scope that returns nothing.
      # This is built into ActiveRecord 4, but not 3
      unless self.class.respond_to? :none
        def self.none
          where(arel_table[:id].eq(nil).and(arel_table[:id].not_eq(nil)))
        end
      end
    end
    
    module ClassMethods
      def acts_as_group(opts = {})
        include Groupify::ActiveRecord::Group

        if (member_klass = opts.delete :default_members)
          self.default_member_class = member_klass.to_s.classify.constantize
        end
        
        if (member_klasses = opts.delete :members)
          member_klasses.each do |member_klass|
            has_members(member_klass)
          end
        end
      end
      
      def acts_as_group_member(opts = {})
        @group_class_name = opts[:class_name] || 'Group'
        include Groupify::ActiveRecord::GroupMember
      end
      
      def acts_as_named_group_member(opts = {})
        include Groupify::ActiveRecord::NamedGroupMember
      end

      def acts_as_group_membership(opts = {})
        include Groupify::ActiveRecord::GroupMembership
      end
    end

    # Usage:
    #    class Group < ActiveRecord::Base
    #        acts_as_group, :members => [:users]
    #        ...
    #    end
    #
    #   group.add(member)
    #
    module Group
      extend ActiveSupport::Concern
      
      included do
        @default_member_class = nil
        @member_klasses ||= Set.new
        has_many :group_memberships, :dependent => :destroy
      end

      def member_classes
        self.class.member_classes
      end
      
      def add(*members)
        members.flatten.each do |member|
          member.groups << self
        end
      end

      # Merge a source group into this group.
      def merge!(source)
        self.class.merge!(source, self)
      end
      
      module ClassMethods
        def with_member(member)
          #joins(:group_memberships).where(:group_memberships => {:member_id => member.id, :member_type => member.class.to_s})
          member.groups
        end
        <commit_msg>Fixed association cache issue with ActiveRecord > 3.13<commit_after>require 'active_record'
require 'set'

# Groups and members
module Groupify
  module ActiveRecord
    extend ActiveSupport::Concern
    
    included do
      # Define a scope that returns nothing.
      # This is built into ActiveRecord 4, but not 3
      unless self.class.respond_to? :none
        def self.none
          where(arel_table[:id].eq(nil).and(arel_table[:id].not_eq(nil)))
        end
      end
    end
    
    module ClassMethods
      def acts_as_group(opts = {})
        include Groupify::ActiveRecord::Group

        if (member_klass = opts.delete :default_members)
          self.default_member_class = member_klass.to_s.classify.constantize
        end
        
        if (member_klasses = opts.delete :members)
          member_klasses.each do |member_klass|
            has_members(member_klass)
          end
        end
      end
      
      def acts_as_group_member(opts = {})
        @group_class_name = opts[:class_name] || 'Group'
        include Groupify::ActiveRecord::GroupMember
      end
      
      def acts_as_named_group_member(opts = {})
        include Groupify::ActiveRecord::NamedGroupMember
      end

      def acts_as_group_membership(opts = {})
        include Groupify::ActiveRecord::GroupMembership
      end
    end

    # Usage:
    #    class Group < ActiveRecord::Base
    #        acts_as_group, :members => [:users]
    #        ...
    #    end
    #
    #   group.add(member)
    #
    module Group
      extend ActiveSupport::Concern
      
      included do
        @default_member_class = nil
        @member_klasses ||= Set.new
        has_many :group_memberships, :dependent => :destroy
      end

      def member_classes
        self.class.member_classes
      end
      
      def add(*members)
        clear_association_cache
        
        members.flatten.each do |member|
          member.groups << self
        end
      end

      # Merge a source group into this group.
      def merge!(source)
        self.class.merge!(source, self)
      end
      
      module ClassMethods
        def with_member(member)
          #joins(:group_memberships).where(:group_memberships => {:member_id => member.id, :member_type => member.class.to_s})
          member.groups
        end
        
{'fraction_non_alphanumeric': 0.08318739054290718, 'fraction_numerical': 0.001532399299474606, 'mean_word_length': 2.0439706862091938, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '6871975', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1304, 'n_words': 291}