Class: Authorize::Redis::Set

Inherits:
Base
  • Object
show all
Defined in:
lib/authorize/redis/set.rb

Direct Known Subclasses

Graph::Graph, ModelSet

Constant Summary

Constants inherited from Base

Base::NAMESPACE_SEPARATOR

Instance Attribute Summary

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods inherited from Base

#==, #_dump, _load, connection, connection_base?, connection_manager, #db, #destroy, #eql?, exists?, #exists?, generate_key, #hash, index, load, load_all, #logger, #method_missing, new, next_counter, #reload, #respond_to?, subordinate_key, #subordinate_key, #to_yaml

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Authorize::Redis::Base

Instance Method Details

#<<(v) ⇒ Object



14
15
16
# File 'lib/authorize/redis/set.rb', line 14

def <<(v)
  add(v)
end

#__getobj__Object



37
38
39
# File 'lib/authorize/redis/set.rb', line 37

def __getobj__
  db.smembers(id).to_set
end

#add(v) ⇒ Object



10
11
12
# File 'lib/authorize/redis/set.rb', line 10

def add(v)
  db.sadd(id, v)
end

#delete(v) ⇒ Object



18
19
20
# File 'lib/authorize/redis/set.rb', line 18

def delete(v)
  db.srem(id, v)
end

#first(n = 1) ⇒ Object



32
33
34
35
# File 'lib/authorize/redis/set.rb', line 32

def first(n = 1)
  return method_missing(:first, n) unless n == 1
  sample(n)
end

#include?(v) ⇒ Boolean Also known as: member?

Returns:

  • (Boolean)


22
23
24
# File 'lib/authorize/redis/set.rb', line 22

def include?(v)
  db.sismember(id, v)
end

#sample(n = 1) ⇒ Object



27
28
29
30
# File 'lib/authorize/redis/set.rb', line 27

def sample(n = 1)
  return method_missing(:sample, n) unless n == 1
  db.srandmember(id)
end

#valid?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/authorize/redis/set.rb', line 6

def valid?
  %w(none set).include?(db.type(id))
end