Sha256: c18f03a0035f0038fc02d5df0fbd8075d30f4b83d44f6c5342b6fa78efce4083

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Tasks
  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

1 entries across 1 versions & 1 rubygems

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