Sha256: 42d6b4fcc75ed6dbcc2e8ff94d1d3f9fe23f2389a1ea0f2d7d413ed1cff4ec44

Contents?: true

Size: 851 Bytes

Versions: 18

Compression:

Stored size: 851 Bytes

Contents

module SoftDeletion
  module Setup

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      # When you call this, it will include the core module and its methods
      #
      # Options:
      #
      # *default_scope*, value: true/false
      # If true, it will also define a default scope
      #
      # It will check if the column "deleted_at" exist before applying default scope
      def has_soft_deletion(options={})
        include SoftDeletion::Core

        if options[:default_scope]
          self.soft_delete_default_scope = name
          default_scope do
            if Thread.current[:"soft_deletion_with_deleted_#{soft_delete_default_scope}"]
              where(nil)
            else
              where(deleted_at: nil)
            end
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
soft_deletion-1.12.0 lib/soft_deletion/setup.rb
soft_deletion-1.11.0 lib/soft_deletion/setup.rb
soft_deletion-1.10.0 lib/soft_deletion/setup.rb
soft_deletion-1.9.0 lib/soft_deletion/setup.rb
soft_deletion-1.8.0 lib/soft_deletion/setup.rb
soft_deletion-1.7.0 lib/soft_deletion/setup.rb
soft_deletion-1.6.0 lib/soft_deletion/setup.rb
soft_deletion-1.5.0 lib/soft_deletion/setup.rb
soft_deletion-1.4.0 lib/soft_deletion/setup.rb
soft_deletion-1.3.1 lib/soft_deletion/setup.rb
soft_deletion-1.3.0 lib/soft_deletion/setup.rb
soft_deletion-1.2.1 lib/soft_deletion/setup.rb
soft_deletion-1.2.0 lib/soft_deletion/setup.rb
soft_deletion-1.1.0 lib/soft_deletion/setup.rb
soft_deletion-1.0.0 lib/soft_deletion/setup.rb
soft_deletion-0.8.3 lib/soft_deletion/setup.rb
soft_deletion-0.8.2 lib/soft_deletion/setup.rb
soft_deletion-0.8.1 lib/soft_deletion/setup.rb