Sha256: 03c35304707f6ff950ffa292e9b8bc27ba60872d61ed2da24adee1a2105f3593

Contents?: true

Size: 772 Bytes

Versions: 1

Compression:

Stored size: 772 Bytes

Contents

module ActiveManageable
  module Methods
    module Destroy
      extend ActiveSupport::Concern

      included do
        include ActiveManageable::Methods::Auxiliary::Includes
      end

      def destroy(id:, options: {})
        initialize_state(options: options)

        @target = action_scope
        includes(@options[:includes])

        @target = find_object_for_destroy(id: id)
        authorize(record: @target)

        model_class.transaction do
          yield if block_given?
          destroy_object
        rescue ActiveRecord::RecordNotDestroyed
          false
        end
      end

      private

      def find_object_for_destroy(id:)
        @target.find(id)
      end

      def destroy_object
        @target.destroy!
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_manageable-0.2.0 lib/active_manageable/methods/destroy.rb