rails-refresher/app/models/concerns/visible.rb

20 lines
322 B
Ruby
Raw Normal View History

2024-07-05 01:00:08 +00:00
module Visible
extend ActiveSupport::Concern
VALID_STATUSES = ['public', 'private', 'archived']
included do
validates :status, inclusion: { in: VALID_STATUSES }
end
class_methods do
def public_count
where(status: 'public').count
end
end
def archived?
status == 'archived'
end
end