Sha256: 7270d59a450e258da8cc23edbb98eaf12cd85160dee6c2896063ad9b531e163b

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Tasuku
  module Taskables::Taskable::Submission
    extend ActiveSupport::Concern

    included do
      scope :by, ->(author) { where author: author }

      after_create do |model|
        if model.request.task.present?
          Tasks::Taskables::Taskable::Response.create do |response|
            response.author = model.author
            response.submittable = model
            response.task = model.request.task
          end
        end
      end

      before_destroy do |model|
        Tasks::Taskables::Taskable::Response.where(
          "submittable_id = ? and submittable_type = ? and author_id = ? and author_type = ?", 
          model.id, model.class.name, model.author.id, model.author.class.name
        ).delete_all
      end
    end

    module ClassMethods
      # Declare the relation the response belongs to.
      #
      # is - A String or Symbol describing the relation that instances of this model
      #      are responses for.
      #
      # This method really only aliases the relation to 'request' so as to promote a
      # common interface for any submission.
      def request is: nil
        alias_method :request, is
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tasuku-1.0.1 app/models/tasuku/taskables/taskable/submission.rb
tasuku-0.1.1 app/models/tasuku/taskables/taskable/submission.rb
tasuku-0.1.0 app/models/tasuku/taskables/taskable/submission.rb