Sha256: eb62ecfa54c188e843e1120ab17171b09f09b76c8d4ce7be75a4d289a775729d

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

module Tasks
  module Taskables::Taskable
    extend ActiveSupport::Concern

    # Determine whether the task has been completed by the given author.
    #
    # author - Any model that can complete tasks.
    #
    # Returns a Boolean.
    def completed_by? author
      !!responses.find_by(author: author)
    end

    included do
      has_one :task, as: :taskable, class_name: '::Tasks::Task', dependent: :destroy
    end

    module ClassMethods
      # Declare the relation for responses.
      #
      # are - A model that represents submissions.
      #
      # This method really only aliases the name of the taskable's join model
      # between authors and tasks to 'responses' so as to promote a common interface
      # for any taskable.
      def responses are: nil
        alias_method :responses, are
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tasuku-0.0.1 app/models/tasks/taskables/taskable.rb