Class: Aclatraz::Store::Mongo
- Inherits:
-
Object
- Object
- Aclatraz::Store::Mongo
show all
- Includes:
- Helpers
- Defined in:
- lib/aclatraz/store/mongo.rb
Overview
For MongoDB, each role is stored in separate row:
{"roles" => [
{"suspect" => 1, "role" => "admin" },
{"suspect" => 2, "role" => "manager/ClassName" },
{"suspect" => 3, "role" => "owner/ClassName/1" }
]}
Constant Summary
collapse
- ROLE_KEY =
"role"
- SUSPECT_KEY =
"suspect"
Instance Method Summary
collapse
Methods included from Helpers
#camelize, #pack, #suspect_id, #unpack
Constructor Details
#initialize(collection, mongo) ⇒ Mongo
Returns a new instance of Mongo.
18
19
20
21
|
# File 'lib/aclatraz/store/mongo.rb', line 18
def initialize(collection, mongo)
@backend = mongo
@collection = collection
end
|
Instance Method Details
#check(role, suspect, object = nil) ⇒ Object
35
36
37
38
39
|
# File 'lib/aclatraz/store/mongo.rb', line 35
def check(role, suspect, object=nil)
@backend[@collection].find(make_doc(role, suspect, object)).map.empty? == false or begin
object && !object.is_a?(Class) ? check(role, suspect, object.class) : false
end
end
|
#clear ⇒ Object
45
46
47
|
# File 'lib/aclatraz/store/mongo.rb', line 45
def clear
@backend[@collection].remove
end
|
#delete(role, suspect, object = nil) ⇒ Object
41
42
43
|
# File 'lib/aclatraz/store/mongo.rb', line 41
def delete(role, suspect, object=nil)
@backend[@collection].remove(make_doc(role, suspect, object))
end
|
#roles(suspect = nil) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/aclatraz/store/mongo.rb', line 27
def roles(suspect=nil)
if suspect
@backend[@collection].find(SUSPECT_KEY => suspect_id(suspect)).map {|row| row[ROLE_KEY] }
else
@backend[@collection].find.map {|row| row[ROLE_KEY] }
end.compact.uniq
end
|
#set(role, suspect, object = nil) ⇒ Object
23
24
25
|
# File 'lib/aclatraz/store/mongo.rb', line 23
def set(role, suspect, object=nil)
@backend[@collection].insert(make_doc(role, suspect, object))
end
|