Sha256: fc6828b0c89088e667727843eb0b8e8b42737330cff3381838749bbdb4ac80f4

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 Bytes

Contents

class Bastet::Base
  attr_accessor :redis

  def initialize redis
    @redis = redis
  end

  def activate feature, target
    act :sadd, feature, target
  end

  def deactivate feature, target
    act :srem, feature, target
  end

  def active? feature, target
    act :sismember, feature, target
  end

  def inactive? feature, target
    !active? feature, target
  end

  private

    def act method, feature, target
      @redis.send(method, key(feature, target), val(target))
    end

    def key feature, target
      [].tap do |key|
        key << "feature"
        key << feature.to_s
        key << namespace(target)
      end.join(":")
    end

    def val target
     instance?(target) ? target.id : target.to_s
    end

    def namespace target
      instance?(target) ? "users" : "groups"
    end

    def instance? target
      target.respond_to?(:id)
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bastet-0.0.2 lib/bastet/base.rb
bastet-0.0.1 lib/bastet/base.rb