Sha256: 886d1e3616815bb89fa5975d3b6ee1218f9ca92af16ec577acd2a90bd6d3df48

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

module Approval
  module Mixins
    module User
      extend ActiveSupport::Concern

      included do
        has_many :approval_requests, class_name: :"Approval::Request", foreign_key: :request_user_id
        has_many :approval_comments, class_name: :"Approval::Comment", foreign_key: :user_id

        Approval::Request.define_user_association(self)
        Approval::Comment.define_user_association(self)
      end

      def request_for_create(records, reason:)
        Approval::RequestForm::Create.new(user: self, reason: reason, records: records)
      end

      def request_for_update(records, reason:)
        Approval::RequestForm::Update.new(user: self, reason: reason, records: records)
      end

      def request_for_destroy(records, reason:)
        Approval::RequestForm::Destroy.new(user: self, reason: reason, records: records)
      end

      def cancel_request(request, reason:)
        Approval::RespondForm::Cancel.new(user: self, reason: reason, request: request)
      end

      def approve_request(request, reason:)
        Approval::RespondForm::Approve.new(user: self, reason: reason, request: request)
      end

      def reject_request(request, reason:)
        Approval::RespondForm::Reject.new(user: self, reason: reason, request: request)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
approval-0.3.1 lib/approval/mixins/user.rb
approval-0.3.0 lib/approval/mixins/user.rb