<commit_before>module ActsAsFollower #:nodoc:
  module Follower

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def acts_as_follower
        has_many :follows, :as => :follower, :dependent => :destroy
        include ActsAsFollower::Follower::InstanceMethods
        include ActsAsFollower::FollowerLib
      end
    end

    module InstanceMethods

      # Returns true if this instance is following the object passed as an argument.
      def following?(followable)
        0 < Follow.unblocked.for_follower(self).for_followable(followable).count
      end

      # Returns the number of objects this instance is following.
      def follow_count
        Follow.unblocked.for_follower(self).count
      end

      # Creates a new follow record for this instance to follow the passed object.
      # Does not allow duplicate records to be created.
      def follow(followable)
        if self != followable
          self.follows.find_or_create_by(followable_id: followable.id, followable_type: parent_class_name(followable))
        end
      end

      # Deletes the follow record if it exists.
      def stop_following(followable)
        if follow = get_follow(followable)
          follow.destroy
        end
      end

      # returns the follows records to the current instance
      def follows_scoped
        self.follows.unblocked.includes(:followable)
      end

      # Returns the follow records related to this instance by type.
      def follows_by_type(followable_type, options={})
        follows_scope  = follows_scoped.for_followable_type(followable_type)
        follows_scope = apply_options_to_scope(follows_scope, options)
      end

      # Returns the follow records related to this instance with the followable included.
      def all_follows(options={})<commit_msg>Uses first_or_create in Follower#follow<commit_after>module ActsAsFollower #:nodoc:
  module Follower

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def acts_as_follower
        has_many :follows, :as => :follower, :dependent => :destroy
        include ActsAsFollower::Follower::InstanceMethods
        include ActsAsFollower::FollowerLib
      end
    end

    module InstanceMethods

      # Returns true if this instance is following the object passed as an argument.
      def following?(followable)
        0 < Follow.unblocked.for_follower(self).for_followable(followable).count
      end

      # Returns the number of objects this instance is following.
      def follow_count
        Follow.unblocked.for_follower(self).count
      end

      # Creates a new follow record for this instance to follow the passed object.
      # Does not allow duplicate records to be created.
      def follow(followable)
        if self != followable
          params = {followable_id: followable.id, followable_type: parent_class_name(followable)}
          self.follows.where(params).first_or_create!
        end
      end

      # Deletes the follow record if it exists.
      def stop_following(followable)
        if follow = get_follow(followable)
          follow.destroy
        end
      end

      # returns the follows records to the current instance
      def follows_scoped
        self.follows.unblocked.includes(:followable)
      end

      # Returns the follow records related to this instance by type.
      def follows_by_type(followable_type, options={})
        follows_scope  = follows_scoped.for_followable_type(followable_type)
        follows_scope = apply_options_to_scope(follows_scope, options)
      end

      # Returns the follow records related to this instance with the followable included.
      def all_follows(options={})
{'fraction_non_alphanumeric': 0.057112356551908196, 'fraction_numerical': 0.0005337603416066186, 'mean_word_length': 2.8167006109979633, 'pattern_counts': {'":': 0, '<': 5, '<?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': '950055', 'n_tokens_mistral': 1036, 'n_tokens_neox': 990, 'n_words': 306}