roles_for_mongoid 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/roles_for_mongoid/strategies/role_relations.rb +18 -13
- data/roles_for_mongoid.gemspec +72 -0
- data/sandbox/test.rb +5 -6
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -11,19 +11,24 @@ module Mongoid::RoleRelations
|
|
11
11
|
in_roles(role_name)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
# def in_roles(*roles)
|
25
|
-
# role_ids = Role.where(:name => roles.flatten).to_a
|
26
|
-
# where(:roles.in => role_ids).to_a
|
14
|
+
# old way!
|
15
|
+
# def in_roles *role_names
|
16
|
+
# roles = Role.where(:name.in => role_names.flatten).to_a
|
17
|
+
# arr_ids = roles.map{|role| role._id}
|
18
|
+
# all.to_a.select do |user|
|
19
|
+
# user.roles.to_a.any? do |role|
|
20
|
+
# arr_ids.include?(role._id)
|
21
|
+
# end
|
22
|
+
# end
|
27
23
|
# end
|
24
|
+
|
25
|
+
def in_roles(*role_names)
|
26
|
+
begin
|
27
|
+
role_ids = Role.where(:name.in => role_names.flatten).to_a.map(&:_id)
|
28
|
+
criteria.in(:role_ids => role_ids).to_a
|
29
|
+
rescue
|
30
|
+
return []
|
31
|
+
end
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{roles_for_mongoid}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-02}
|
13
|
+
s.description = %q{Facilitates adding Roles to your Mongoid user models}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/generators/mongoid/roles/roles_generator.rb",
|
27
|
+
"lib/roles_for_mongoid.rb",
|
28
|
+
"lib/roles_for_mongoid/role.rb",
|
29
|
+
"lib/roles_for_mongoid/strategies/admin_flag.rb",
|
30
|
+
"lib/roles_for_mongoid/strategies/inline_role.rb",
|
31
|
+
"lib/roles_for_mongoid/strategies/inline_roles.rb",
|
32
|
+
"lib/roles_for_mongoid/strategies/role_relations.rb",
|
33
|
+
"lib/roles_for_mongoid/strategies/roles_mask.rb",
|
34
|
+
"lib/roles_for_mongoid/user.rb",
|
35
|
+
"roles_for_mongoid.gemspec",
|
36
|
+
"sandbox/test.rb",
|
37
|
+
"spec/roles_for_mongoid/user_admin_field_spec.rb",
|
38
|
+
"spec/roles_for_mongoid/user_inline_role_spec.rb",
|
39
|
+
"spec/roles_for_mongoid/user_inline_roles_spec.rb",
|
40
|
+
"spec/roles_for_mongoid/user_role_relations_spec.rb",
|
41
|
+
"spec/roles_for_mongoid/user_roles_mask_spec.rb",
|
42
|
+
"spec/spec.opts",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
s.homepage = %q{http://github.com/kristianmandrup/roles_for_mm}
|
46
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = %q{1.3.7}
|
49
|
+
s.summary = %q{Facilitates adding Roles to your Mongoid user models}
|
50
|
+
s.test_files = [
|
51
|
+
"spec/roles_for_mongoid/user_admin_field_spec.rb",
|
52
|
+
"spec/roles_for_mongoid/user_inline_role_spec.rb",
|
53
|
+
"spec/roles_for_mongoid/user_inline_roles_spec.rb",
|
54
|
+
"spec/roles_for_mongoid/user_role_relations_spec.rb",
|
55
|
+
"spec/roles_for_mongoid/user_roles_mask_spec.rb",
|
56
|
+
"spec/spec_helper.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.17"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.17"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.17"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/sandbox/test.rb
CHANGED
@@ -22,11 +22,10 @@ class User
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# end
|
25
|
+
def self.get_roles(*ids)
|
26
|
+
arr = ids.flatten
|
27
|
+
criteria.in(:role_ids => arr).to_a
|
28
|
+
end
|
30
29
|
|
31
30
|
end
|
32
31
|
|
@@ -45,4 +44,4 @@ role_id = user.roles.to_a.first._id
|
|
45
44
|
|
46
45
|
p role_id
|
47
46
|
p User.find_roles role_id
|
48
|
-
|
47
|
+
p User.get_roles role_id
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/roles_for_mongoid/strategies/role_relations.rb
|
60
60
|
- lib/roles_for_mongoid/strategies/roles_mask.rb
|
61
61
|
- lib/roles_for_mongoid/user.rb
|
62
|
+
- roles_for_mongoid.gemspec
|
62
63
|
- sandbox/test.rb
|
63
64
|
- spec/roles_for_mongoid/user_admin_field_spec.rb
|
64
65
|
- spec/roles_for_mongoid/user_inline_role_spec.rb
|