Sha256: 6fa1b1d1d2fe8f0c3144e5117744d092e55a06efca17d066dc35c1aea75c283b
Contents?: true
Size: 1.14 KB
Versions: 40
Compression:
Stored size: 1.14 KB
Contents
#!/usr/bin/env ruby require 'set' require 'redis' module Flapjack module Data class Tag < ::Set attr_accessor :name def initialize(opts = {}) raise "Redis connection not set" unless @redis = opts[:redis] @name = opts[:name] preset = @redis.smembers(@name) enum = opts[:create] || [] @redis.sadd(@name, enum) unless enum.empty? super(enum | preset) end def self.find(name, opts) self.new(:name => name, :redis => opts[:redis]) end def self.find_intersection(tags, opts) @redis = opts[:redis] @redis.sinter(tags) end def self.create(name, enum = [], opts) self.new(:name => name, :create => enum, :redis => opts[:redis]) end def add(o) @redis.sadd(@name, o) unless o.empty? super(o) end def delete(o) @redis.srem(@name, o) super(o) end def merge(o) @redis.sadd(@name, o) unless o.empty? super(o) end def to_json(*a) self.to_a.to_json(*a) end end end end
Version data entries
40 entries across 40 versions & 1 rubygems