Sha256: 01989ea9f3126a901ccc339745799c2d0cba587ef6c805e449842aa8e772e8fa

Contents?: true

Size: 713 Bytes

Versions: 3

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true

module Talkie
  module ActsAsTalker
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def acts_as_talker
        class_eval do
          has_many :comments, as: :creator,
                              class_name: 'Talkie::Comment',
                              inverse_of: :creator

          def owns_comment?(comment)
            self == comment.creator
          end
        end
      end

      alias_method :acts_as_commentator, :acts_as_talker
      alias_method :acts_as_speaker, :acts_as_talker
      alias_method :acts_as_commenter, :acts_as_talker
    end
  end
end

ActiveRecord::Base.send :include, Talkie::ActsAsTalker

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
talkie-0.2.0 lib/talkie/acts_as_talker.rb
talkie-0.1.1 lib/talkie/acts_as_talker.rb
talkie-0.1.0 lib/talkie/acts_as_talker.rb