Sha256: 308b04a98cd533ee875da96a38406f0ae42046511b415be2b9577ce646cccef7

Contents?: true

Size: 514 Bytes

Versions: 22

Compression:

Stored size: 514 Bytes

Contents

# frozen_string_literal: true
class FeaturedWork < ActiveRecord::Base
  FEATURE_LIMIT = 5
  validate :count_within_limit, on: :create
  validates :order, inclusion: { in: proc { 0..FEATURE_LIMIT } }

  default_scope { order(:order) }

  def count_within_limit
    return if FeaturedWork.can_create_another?
    errors.add(:base, "Limited to #{FEATURE_LIMIT} featured works.")
  end

  attr_accessor :presenter

  class << self
    def can_create_another?
      FeaturedWork.count < FEATURE_LIMIT
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/models/featured_work.rb
hyrax-5.0.0.rc1 app/models/featured_work.rb
hyrax-3.6.0 app/models/featured_work.rb
hyrax-4.0.0 app/models/featured_work.rb
hyrax-4.0.0.rc3 app/models/featured_work.rb
hyrax-4.0.0.rc2 app/models/featured_work.rb
hyrax-4.0.0.rc1 app/models/featured_work.rb
hyrax-3.5.0 app/models/featured_work.rb
hyrax-4.0.0.beta2 app/models/featured_work.rb
hyrax-3.4.2 app/models/featured_work.rb
hyrax-4.0.0.beta1 app/models/featured_work.rb
hyrax-3.4.1 app/models/featured_work.rb
hyrax-3.4.0 app/models/featured_work.rb
hyrax-3.3.0 app/models/featured_work.rb
hyrax-3.2.0 app/models/featured_work.rb
hyrax-3.1.0 app/models/featured_work.rb
hyrax-3.0.2 app/models/featured_work.rb
hyrax-3.0.1 app/models/featured_work.rb
hyrax-3.0.0 app/models/featured_work.rb
hyrax-3.0.0.pre.rc4 app/models/featured_work.rb