Class: Usage

Inherits:
ApplicationRecord show all
Defined in:
app/models/usage.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token

Methods included from WithPgLock

#with_pg_lock

Class Method Details

.destroy_all_where(query) ⇒ Object



13
14
15
# File 'app/models/usage.rb', line 13

def self.destroy_all_where(query)
  where(query).destroy_all
end

.destroy_usages_for(record) ⇒ Object



17
18
19
# File 'app/models/usage.rb', line 17

def self.destroy_usages_for(record)
  destroy_all_where(parent_item: record)
end

Instance Method Details

#destroy_children_usages!Object



21
22
23
# File 'app/models/usage.rb', line 21

def destroy_children_usages!
  item.structural_children.each { |child| Usage.destroy_all_where(parent_item: child, organization: organization) }
end

#index_children!(children) ⇒ Object



25
26
27
# File 'app/models/usage.rb', line 25

def index_children!(children)
  children.each { |it| it.index_usage! organization }
end