Sha256: 5b78c415ea94aecb919a341522756a9b26f2df0784c7336f6711d4ab13bcd571

Contents?: true

Size: 770 Bytes

Versions: 14

Compression:

Stored size: 770 Bytes

Contents

module WithContent
  extend ActiveSupport::Concern

  included do
    before_destroy :destroy_usages!
  end

  class_methods do
    def associated_content(content_name)
      belongs_to content_name
      validates_presence_of content_name

      alias_method :content, content_name

      define_method(:associated_content_name) { content_name }
    end
  end

  def progress_for(user, organization=Organization.current)
    content.progress_for(user, organization)
  end

  private

  # Generally we are calling progress_for for each sibling. That method needs the
  # content. With this includes call we're avoiding the N + 1 queries.
  def siblings
    super.includes(associated_content_name)
  end

  def destroy_usages!
    Usage.destroy_usages_for self
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
mumuki-laboratory-7.5.2 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-ad16a5930cec/app/models/concerns/with_content.rb
mumuki-laboratory-7.5.1 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-a059418e5fd8/app/models/concerns/with_content.rb
mumuki-domain-7.5.1 app/models/concerns/with_content.rb
mumuki-laboratory-7.5.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-acb12583b793/app/models/concerns/with_content.rb
mumuki-domain-7.5.0 app/models/concerns/with_content.rb
mumuki-domain-7.4.1 app/models/concerns/with_content.rb
mumuki-domain-7.4.0 app/models/concerns/with_content.rb
mumuki-domain-7.3.2 app/models/concerns/with_content.rb
mumuki-domain-7.3.1 app/models/concerns/with_content.rb
mumuki-domain-7.2.3 app/models/concerns/with_content.rb
mumuki-domain-7.3.0 app/models/concerns/with_content.rb
mumuki-domain-7.2.2 app/models/concerns/with_content.rb
mumuki-domain-7.2.1 app/models/concerns/with_content.rb
mumuki-domain-7.2.0 app/models/concerns/with_content.rb