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.3.14 lib/concerns/ants/hideable.rb
ants-0.3.13 lib/concerns/ants/hideable.rb
ants-0.3.12 lib/concerns/ants/hideable.rb
ants-0.3.11 lib/concerns/ants/hideable.rb
ants-0.3.10 lib/concerns/ants/hideable.rb
ants-0.3.9 lib/concerns/ants/hideable.rb
ants-0.3.5 lib/concerns/ants/hideable.rb
ants-0.3.4 lib/concerns/ants/hideable.rb
ants-0.3.3 lib/concerns/ants/hideable.rb
ants-0.3.2 lib/concerns/ants/hideable.rb
ants-0.3.1 lib/concerns/ants/hideable.rb
ants-0.3.0 lib/concerns/ants/hideable.rb
ants-0.2.8 lib/concerns/ants/hideable.rb
ants-0.2.7 lib/concerns/ants/hideable.rb
ants-0.2.6 lib/concerns/ants/hideable.rb
ants-0.2.5 lib/concerns/ants/hideable.rb
ants-0.2.4 lib/concerns/ants/hideable.rb
ants-0.2.3 lib/concerns/ants/hideable.rb
ants-0.2.2 lib/concerns/ants/hideable.rb
ants-0.2.1 lib/concerns/ants/hideable.rb