Class: CrudComponents::Admin::Dependents

Inherits:
Object
  • Object
show all
Defined in:
lib/crud_components/admin/dependents.rb

Overview

What else goes when a record is destroyed: the associations that declare a dependent: behaviour, counted, plus the ones that would block it.

Defined Under Namespace

Classes: Item, Selection

Constant Summary collapse

DESTROYING =
%i[destroy destroy_async delete_all].freeze
BLOCKING =
%i[restrict_with_error restrict_with_exception].freeze
PREVIEW =

How many of an item's records the confirmation page names.

10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Dependents

Returns a new instance of Dependents.



51
52
53
# File 'lib/crud_components/admin/dependents.rb', line 51

def initialize(record)
  @record = record
end

Class Method Details

.for(record) ⇒ Object



49
# File 'lib/crud_components/admin/dependents.rb', line 49

def self.for(record) = new(record).items

Instance Method Details

#blockersObject

Anything that blocks the delete outright.



60
# File 'lib/crud_components/admin/dependents.rb', line 60

def blockers = items.select(&:blocks?)

#itemsObject



55
56
57
# File 'lib/crud_components/admin/dependents.rb', line 55

def items
  @items ||= (association_items + attachment_items).reject { |item| item.count.zero? }
end