Module: Kamikakushi::Kaonashi::ClassMethods

Defined in:
lib/kamikakushi/kaonashi.rb

Instance Method Summary collapse

Instance Method Details

#kaonashi(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kamikakushi/kaonashi.rb', line 6

def kaonashi(options = {})
  define_singleton_method(:dependent_parent_name) { options[:parent] }
  return unless dependent_parent_name

  class_eval do
    include InstanceMethods
    default_scope { without_deleted }
    alias_method_chain :destroyed?, :kaonashi

    scope :with_deleted, -> {
      join_with_dependent_parent(dependent_parent_name, :with_deleted)
    }

    scope :without_deleted, -> {
      join_with_dependent_parent(dependent_parent_name, :without_deleted)
    }

    scope :only_deleted, -> {
      join_with_dependent_parent(dependent_parent_name, :only_deleted)
    }
  end
end