Class: Maxwell::Agent::RedisObjects::Set
- Inherits:
-
Object
- Object
- Maxwell::Agent::RedisObjects::Set
- Includes:
- Maxwell::Agent::RedisObjects
- Defined in:
- lib/maxwell/agent/redis_objects/set.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(object) ⇒ Object
- #all ⇒ Object
- #count ⇒ Object
- #exists?(object) ⇒ Boolean
- #find_by(key, value) ⇒ Object
-
#initialize(name) ⇒ Set
constructor
A new instance of Set.
- #remove(object) ⇒ Object
Methods included from Maxwell::Agent::RedisObjects
Constructor Details
#initialize(name) ⇒ Set
Returns a new instance of Set.
8 9 10 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 8 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 6 def name @name end |
Instance Method Details
#add(object) ⇒ Object
12 13 14 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 12 def add(object) redis {|redis| redis.sadd name, object.to_json } end |
#all ⇒ Object
20 21 22 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 20 def all redis {|redis| redis.smembers name} end |
#count ⇒ Object
24 25 26 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 24 def count redis {|redis| redis.scard name } end |
#exists?(object) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 28 def exists?(object) if redis {|redis| redis.sismember name, object.to_json } true else false end end |
#find_by(key, value) ⇒ Object
36 37 38 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 36 def find_by(key, value) all.reject {|host| host if host.key != value } end |
#remove(object) ⇒ Object
16 17 18 |
# File 'lib/maxwell/agent/redis_objects/set.rb', line 16 def remove(object) redis {|redis| redis.srem name, object.to_json } end |