Sha256: fae2cdcf624572c77523ccc2395d12b2bce0d8e60b2ab5b0d7cca0cac03461f7

Contents?: true

Size: 484 Bytes

Versions: 72

Compression:

Stored size: 484 Bytes

Contents

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

72 entries across 72 versions & 3 rubygems

Version Path
hyrax-2.9.6 app/models/featured_work.rb
hyrax-2.9.5 app/models/featured_work.rb
hyrax-2.9.4 app/models/featured_work.rb
hyrax-2.9.3 app/models/featured_work.rb
hyrax-2.9.2 app/models/featured_work.rb
hyrax-2.9.1 app/models/featured_work.rb
hyrax-2.9.0 app/models/featured_work.rb
hyrax-2.8.0 app/models/featured_work.rb
hyrax-2.7.2 app/models/featured_work.rb
hyrax-2.7.1 app/models/featured_work.rb
hyrax-2.7.0 app/models/featured_work.rb
hyrax-2.6.0 app/models/featured_work.rb
hyrax-3.0.0.pre.rc1 app/models/featured_work.rb
hyrax-3.0.0.pre.beta3 app/models/featured_work.rb
hyrax-2.5.1 app/models/featured_work.rb
hyrax-2.5.0 app/models/featured_work.rb
hyrax-3.0.0.pre.beta2 app/models/featured_work.rb
hyrax-2.4.1 app/models/featured_work.rb
hyrax-3.0.0.pre.beta1 app/models/featured_work.rb
hyrax-2.4.0 app/models/featured_work.rb