Sha256: c8326c4840ec83d6f12490b39393f25b00e3b746d5be3b67688bf29669a301e1

Contents?: true

Size: 659 Bytes

Versions: 6

Compression:

Stored size: 659 Bytes

Contents

module Ants
  module Featurable
    extend ActiveSupport::Concern
    included do
      ## Attributes
      field :featured, type: Boolean, default: false

      ## Scopes
      scope :featured,     -> { where(featured: true) }
      scope :not_featured, -> { where(featured: false) }

      ## Indexes
      index({ featured: 1 })

      ## Helpers
      def featured?
        self.featured
      end

      def set_featured!
        return if self.featured?
        self.featured = true
        self.save!
      end

      def unset_featured!
        return unless self.featured?
        self.featured = false
        self.save!
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ants-0.3.14 lib/concerns/ants/featurable.rb
ants-0.3.13 lib/concerns/ants/featurable.rb
ants-0.3.12 lib/concerns/ants/featurable.rb
ants-0.3.11 lib/concerns/ants/featurable.rb
ants-0.3.10 lib/concerns/ants/featurable.rb
ants-0.3.9 lib/concerns/ants/featurable.rb