Sha256: a514647ac00296f1983c60c7e477ba06d3c4aebe5b3d74f673e54e7654e5c086

Contents?: true

Size: 512 Bytes

Versions: 41

Compression:

Stored size: 512 Bytes

Contents

class FeaturedWork < ActiveRecord::Base
  FEATURE_LIMIT = 5
  validate :count_within_limit, on: :create
  validates :order, inclusion: { in: Proc.new{ 0..FEATURE_LIMIT } }

  default_scope { order(:order) }

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

  attr_accessor :generic_file_solr_document

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

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
sufia-models-6.2.0 app/models/featured_work.rb
sufia-models-6.1.0 app/models/featured_work.rb
sufia-5.0.0 sufia-models/app/models/featured_work.rb
sufia-models-5.0.0 app/models/featured_work.rb
sufia-models-6.0.0 app/models/featured_work.rb
sufia-6.0.0 sufia-models/app/models/featured_work.rb
sufia-6.0.0.rc4 sufia-models/app/models/featured_work.rb
sufia-models-6.0.0.rc4 app/models/featured_work.rb
sufia-6.0.0.rc3 sufia-models/app/models/featured_work.rb
sufia-models-6.0.0.rc3 app/models/featured_work.rb
sufia-5.0.0.rc1 sufia-models/app/models/featured_work.rb
sufia-models-5.0.0.rc1 app/models/featured_work.rb
sufia-6.0.0.rc2 sufia-models/app/models/featured_work.rb
sufia-models-6.0.0.rc2 app/models/featured_work.rb
sufia-6.0.0.rc1 sufia-models/app/models/featured_work.rb
sufia-models-6.0.0.rc1 app/models/featured_work.rb
sufia-4.3.1 sufia-models/app/models/featured_work.rb
sufia-models-4.3.1 app/models/featured_work.rb
sufia-6.0.0.beta1 sufia-models/app/models/featured_work.rb
sufia-models-6.0.0.beta1 app/models/featured_work.rb