Class: Alchemy::DeleteElements

Inherits:
Object
  • Object
show all
Defined in:
app/services/alchemy/delete_elements.rb

Defined Under Namespace

Classes: WouldLeaveOrphansError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ DeleteElements

Returns a new instance of DeleteElements.



9
10
11
# File 'app/services/alchemy/delete_elements.rb', line 9

def initialize(elements)
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



7
8
9
# File 'app/services/alchemy/delete_elements.rb', line 7

def elements
  @elements
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
# File 'app/services/alchemy/delete_elements.rb', line 13

def call
  if orphanable_records.present?
    raise WouldLeaveOrphansError
  end

  Gutentag::Tagging.where(taggable: elements).delete_all
  delete_elements
end