Sha256: 249f6dd7de0a45d032fb73cf086e571cdcddac7febf10133421235c6f5908f5b

Contents?: true

Size: 665 Bytes

Versions: 18

Compression:

Stored size: 665 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

18 entries across 18 versions & 1 rubygems

Version Path
ants-0.3.5 lib/concerns/ants/featurable.rb
ants-0.3.4 lib/concerns/ants/featurable.rb
ants-0.3.3 lib/concerns/ants/featurable.rb
ants-0.3.2 lib/concerns/ants/featurable.rb
ants-0.3.1 lib/concerns/ants/featurable.rb
ants-0.3.0 lib/concerns/ants/featurable.rb
ants-0.2.8 lib/concerns/ants/featurable.rb
ants-0.2.7 lib/concerns/ants/featurable.rb
ants-0.2.6 lib/concerns/ants/featurable.rb
ants-0.2.5 lib/concerns/ants/featurable.rb
ants-0.2.4 lib/concerns/ants/featurable.rb
ants-0.2.3 lib/concerns/ants/featurable.rb
ants-0.2.2 lib/concerns/ants/featurable.rb
ants-0.2.1 lib/concerns/ants/featurable.rb
ants-0.2.0 lib/concerns/ants/featurable.rb
ants-0.1.4 lib/concerns/ants/featurable.rb
ants-0.1.1 lib/concerns/ants/featurable.rb
ants-0.1.0 lib/concerns/ants/featurable.rb