Module HipstersInc::Acts::Filterable::ClassMethods
In: lib/acts_as_filterable.rb

Methods

Included Modules

HipstersInc::Acts::Filterable::InstanceMethods

External Aliases

read_attribute -> old_read_attribute
find -> find_without_access_control

Public Instance methods

The model mixin to let ActiveRecord filter your model object based on rules. The following example makes a badger visible by default, but makes it invisible if its had more than 5 beers, unless its name is ‘Frank‘

 class Badger < ActiveRecord::Base
   has_many :beers
   acts_as_filterable :visible => true # Defaut to visible

   def too_much_beer?
     beers.size > 5
   end

   def is_frank?
     name == 'Frank'
   end

   invisible_if :too_much_beer?
   visible_if   :is_frank?
 end

That should make said badgers invisible from the entire system

[Validate]