Sha256: 6220ddf63c199b1b0a446bdca0b1d1f55b7cfcbe2f346235a97bdcb48775361b

Contents?: true

Size: 624 Bytes

Versions: 24

Compression:

Stored size: 624 Bytes

Contents

module Ants
  module Hideable
    extend ActiveSupport::Concern

    included do
      # attributes
      field :hidden, type: Boolean, default: false

      # scopes
      scope :hidden,     -> { where(hidden: true)  }
      scope :not_hidden, -> { where(hidden: false) }

      # indexes
      index({ hidden: 1 })


      # helpers
      def hidden?
        self.hidden
      end


      def hide!
        return if self.hidden?
        self.hidden = true
        self.save!
      end


      def unhide!
        return unless self.hidden?
        self.hidden = false
        self.save!
      end


    end
  end
end




Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ants-0.2.0 lib/concerns/ants/hideable.rb
ants-0.1.4 lib/concerns/ants/hideable.rb
ants-0.1.1 lib/concerns/ants/hideable.rb
ants-0.1.0 lib/concerns/ants/hideable.rb