Sha256: 1bd0db356d4bc1c4ef6e774d54134e10f2ae083b998cc5a1f270a75f578196d3

Contents?: true

Size: 570 Bytes

Versions: 1

Compression:

Stored size: 570 Bytes

Contents

# frozen_string_literal: true

module InvisibleRecord
  # Define scopes for the invisible record
  module Scopes
    def self.included(base)
      base.extend ClassMethods
    end

    # Define methods for Scopes
    module ClassMethods
      protected

      def define_default_scopes(deleted_ts_attr:)
        default_scope { where(deleted_ts_attr => nil) }
        scope :include_deleted, -> { unscope(where: deleted_ts_attr.to_sym) }
        scope :deleted, -> { unscope(where: deleted_ts_attr.to_sym).where.not(deleted_ts_attr => nil) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invisible_record-0.2.1 lib/invisible_record/scopes.rb