Sha256: b6620a5c7065b771fe5e4ba276dbe666fe1ec8d9bdb8f7590c503cd31276e8d5

Contents?: true

Size: 796 Bytes

Versions: 32

Compression:

Stored size: 796 Bytes

Contents

class Usage < ApplicationRecord
  belongs_to :organization

  belongs_to :item, polymorphic: true
  belongs_to :parent_item, polymorphic: true

  scope :in_organization, ->(organization = Organization.current) { where(organization_id: organization.id) }

  before_save :set_slug
  before_destroy :destroy_children_usages!

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

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

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

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

  private

  def set_slug
    self.slug = item.slug
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
mumuki-domain-7.10.1 app/models/usage.rb
mumuki-domain-7.10.0 app/models/usage.rb
mumuki-laboratory-7.9.2 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-7082a83493eb/app/models/usage.rb
mumuki-domain-7.9.2 app/models/usage.rb
mumuki-laboratory-7.9.1 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-b162dc91aa77/app/models/usage.rb
mumuki-domain-7.9.1 app/models/usage.rb
mumuki-laboratory-7.9.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-520f859ca8af/app/models/usage.rb
mumuki-domain-7.9.0 app/models/usage.rb
mumuki-domain-7.7.3 app/models/usage.rb
mumuki-domain-7.8.1 app/models/usage.rb
mumuki-domain-7.8.0 app/models/usage.rb
mumuki-domain-7.7.2 app/models/usage.rb
mumuki-domain-7.7.1 app/models/usage.rb
mumuki-laboratory-7.7.1 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-cb7a9018bb94/app/models/usage.rb
mumuki-laboratory-7.7.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-cb7a9018bb94/app/models/usage.rb
mumuki-domain-7.7.0 app/models/usage.rb
mumuki-domain-7.6.1 app/models/usage.rb
mumuki-domain-7.6.0 app/models/usage.rb
mumuki-laboratory-7.5.2 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-ad16a5930cec/app/models/usage.rb
mumuki-laboratory-7.5.1 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-a059418e5fd8/app/models/usage.rb