Sha256: 8d13b6995e838ae247dbbef0b64a96669f2940e71b5cb7d70a574c37110d8b3b

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Followability
  module Followable
    def followability?
      false
    end

    # rubocop:disable Metrics/MethodLength
    def followability
      class_eval do
        def self.followability?
          true
        end

        has_many :followerable_relationships,
                 as: :followerable,
                 class_name: 'Followability::Relationship',
                 dependent: :destroy

        has_many :followable_relationships,
                 as: :followable,
                 class_name: 'Followability::Relationship',
                 dependent: :destroy

        has_many :followers,
                 -> { Followability::Relationship.following },
                 through: :followable_relationships,
                 source: :followerable,
                 class_name: name,
                 source_type: name

        has_many :following,
                 -> { Followability::Relationship.following },
                 through: :followerable_relationships,
                 source: :followable,
                 class_name: name,
                 source_type: name

        has_many :blocks,
                 -> { Followability::Relationship.blocked },
                 through: :followerable_relationships,
                 source: :followable,
                 class_name: name,
                 source_type: name
      end

      include Followability::Followable::Associations
      include Followability::Followable::Callbacks
      include Followability::Followable::Actions::Common
      include Followability::Followable::Actions::Follow
      include Followability::Followable::Actions::Block
    end
    # rubocop:enable Metrics/MethodLength
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
followability-1.1.0 lib/followability/followable.rb
followability-1.0.0 lib/followability/followable.rb