Sha256: 69a76841408cd006c826a155d11ce4564c019c7b7f37084c1a458f4e84dcaf9c

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

module Enabler
	module Storage
		class Redis

			attr_reader(:redis)

			def initialize(redis)
				@redis = redis
			end

			def add!(feature, model)
				redis.sadd key(feature, model), model.id
			end

			def remove!(feature, model)
				redis.srem key(feature, model), model.id
			end

			def enabled?(feature, model)
				redis.sismember key(feature, model), model.id 
			end

			private

			def key(feature, model)
				"enabler::#{underscore model.class.to_s}::#{underscore feature.to_s}"
			end

			#taking from active support
			def underscore(string)
				string.gsub(/::/, '/').
					gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
					gsub(/([a-z\d])([A-Z])/,'\1_\2').
					tr("-", "_").
					downcase
			end

		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enabler-0.0.5 lib/enabler/storage/redis.rb
enabler-0.0.4 lib/enabler/storage/redis.rb
enabler-0.0.3 lib/enabler/storage/redis.rb
enabler-0.0.2 lib/enabler/storage/redis.rb