roles_for_mongoid 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source :rubygems
2
+ source 'http://gems.github.com/'
3
+
4
+ group :default do
5
+ gem "mongoid", '~> 2.0.0.beta.18'
6
+ gem 'bson', '~> 1.0.7'
7
+ gem "activesupport", '~> 3.0.0'
8
+ gem "require_all", '~> 1.2.0'
9
+ gem "sugar-high", '~> 0.2.10'
10
+ gem "roles_generic", '~> 0.2.6'
11
+ end
12
+
13
+ group :test do
14
+ gem "rspec", '~> 2.0.0.beta.22'
15
+ end
data/README.markdown CHANGED
@@ -20,12 +20,30 @@ It also implements the following Role strategies:
20
20
 
21
21
  ## Rails generator
22
22
 
23
- Might work but needs testing ;)
23
+ The library comes with a Rails 3 generator that lets you populate a user model with a role strategy of your choice.
24
24
 
25
- Example:
25
+ The following role strategies are included by default. Add your own by adding extra files inside the strategy folder, one file for each role strategy is recommended.
26
26
 
27
- <code>$ rails g mongoid:roles User --strategy admin_flag --roles admin guest</code>
27
+ * admin_flag
28
+ * many_roles
29
+ * one_role
30
+ * roles_mask
31
+ * role_string
32
+ * role_strings
33
+
34
+ *Roles generator*
35
+
36
+ Apply :admin_flag Role strategy to User model using default roles :admin and :guest (default)
37
+
38
+ <code>$ rails g mongoid:roles User --strategy admin_flag</code>
39
+
40
+ Apply :admin_flag Role strategy to User model using default roles and extra role :author
41
+
42
+ <code>$ rails g mongoid:roles_migration User --strategy admin_flag --roles author</code>
43
+
44
+ Apply :one_role Role strategy to User model without default roles, only with roles :user, :special and :editor
28
45
 
46
+ <code>$ rails g mongoid:roles_migration User --strategy one_role --roles user special editor --no-default-roles</code>
29
47
  ## Note on Patches/Pull Requests
30
48
 
31
49
  * Fork the project.
data/Rakefile CHANGED
@@ -7,13 +7,14 @@ begin
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/roles_for_mm"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_development_dependency "rspec", '~> 2.0.0.beta.19'
10
+ gem.add_development_dependency "rspec", '~> 2.0.0.beta.22'
11
11
 
12
- gem.add_dependency "mongoid", '~> 2.0.0.beta.17'
12
+ gem.add_dependency "mongoid", '~> 2.0.0.beta.18'
13
+ gem.add_dependency 'bson', '~> 1.0.7'
13
14
  gem.add_dependency "activesupport", '~> 3.0.0'
14
- gem.add_dependency "require_all", '~> 1.1.0'
15
- gem.add_dependency "sugar-high", '~> 0.2.3'
16
- gem.add_dependency "roles_generic", '~> 0.2.2'
15
+ gem.add_dependency "require_all", '~> 1.2.0'
16
+ gem.add_dependency "sugar-high", '~> 0.2.10'
17
+ gem.add_dependency "roles_generic", '~> 0.2.7'
17
18
 
18
19
  end
19
20
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -34,9 +34,11 @@ module RoleStrategy::Mongoid
34
34
  end
35
35
 
36
36
  # assign roles
37
- def roles=(*roles)
38
- raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
39
- role_relations = role_class.find_roles(*roles)
37
+ def roles=(*_roles)
38
+ _roles = get_roles(_roles)
39
+ return nil if !_roles || _roles.empty?
40
+
41
+ role_relations = role_class.find_roles(_roles)
40
42
  self.send("#{role_attribute}=", role_relations)
41
43
  save
42
44
  end
@@ -30,9 +30,11 @@ module RoleStrategy::Mongoid
30
30
 
31
31
  module Implementation
32
32
  # assign roles
33
- def roles=(*roles)
34
- raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
35
- first_role = roles.flatten.first
33
+ def roles=(*_roles)
34
+ _roles = get_roles(_roles)
35
+ return nil if !_roles || _roles.empty?
36
+
37
+ first_role = _roles.flatten.first
36
38
  role_relation = role_class.find_role(first_role)
37
39
  self.send("#{role_attribute}=", role_relation)
38
40
  one_role.save
@@ -41,8 +43,8 @@ module RoleStrategy::Mongoid
41
43
 
42
44
  # query assigned roles
43
45
  def roles
44
- role = self.send(role_attribute).name.to_sym
45
- [role]
46
+ role = self.send(role_attribute)
47
+ role ? [role.name.to_sym] : []
46
48
  end
47
49
 
48
50
  def roles_list
data/lib/roles_mongoid.rb CHANGED
@@ -2,6 +2,7 @@ require 'roles_generic'
2
2
  require 'require_all'
3
3
  require 'set'
4
4
  require 'sugar-high/array'
5
+ require 'sugar-high/kind_of'
5
6
  require 'mongoid'
6
7
  require 'bson'
7
8
  require 'roles_mongoid/namespaces'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_for_mongoid}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-09-11}
12
+ s.date = %q{2010-09-23}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in Mongoid}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -17,9 +17,11 @@ Gem::Specification.new do |s|
17
17
  "README.markdown"
18
18
  ]
19
19
  s.files = [
20
- ".document",
20
+ ".bundle/config",
21
+ ".document",
21
22
  ".gitignore",
22
23
  ".rspec",
24
+ "Gemfile",
23
25
  "LICENSE",
24
26
  "README.markdown",
25
27
  "Rakefile",
@@ -74,27 +76,30 @@ Gem::Specification.new do |s|
74
76
  s.specification_version = 3
75
77
 
76
78
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
77
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
78
- s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
79
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
80
+ s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.18"])
81
+ s.add_runtime_dependency(%q<bson>, ["~> 1.0.7"])
79
82
  s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
80
- s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
81
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.3"])
82
- s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.2"])
83
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
84
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.10"])
85
+ s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.7"])
83
86
  else
84
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
85
- s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
87
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
88
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.18"])
89
+ s.add_dependency(%q<bson>, ["~> 1.0.7"])
86
90
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
87
- s.add_dependency(%q<require_all>, ["~> 1.1.0"])
88
- s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
89
- s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
91
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
92
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
93
+ s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
90
94
  end
91
95
  else
92
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
93
- s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
96
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
97
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.18"])
98
+ s.add_dependency(%q<bson>, ["~> 1.0.7"])
94
99
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
95
- s.add_dependency(%q<require_all>, ["~> 1.1.0"])
96
- s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
97
- s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
100
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
101
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
102
+ s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
98
103
  end
99
104
  end
100
105
 
@@ -27,7 +27,7 @@ describe "Roles for Mongoid" do
27
27
  @user.save
28
28
 
29
29
  @admin_user = User.create(:name => 'Admin user')
30
- @admin_user.role = :admin
30
+ @admin_user.role = Role.where(:name => :admin).to_a.first
31
31
  @admin_user.save
32
32
  end
33
33
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
1
+ require 'rspec/core'
3
2
  require 'mongoid'
4
3
  require 'roles_mongoid'
5
4
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-11 00:00:00 +02:00
17
+ date: 2010-09-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,8 +30,8 @@ dependencies:
30
30
  - 0
31
31
  - 0
32
32
  - beta
33
- - 19
34
- version: 2.0.0.beta.19
33
+ - 22
34
+ version: 2.0.0.beta.22
35
35
  type: :development
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -47,14 +47,29 @@ dependencies:
47
47
  - 0
48
48
  - 0
49
49
  - beta
50
- - 17
51
- version: 2.0.0.beta.17
50
+ - 18
51
+ version: 2.0.0.beta.18
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
55
- name: activesupport
55
+ name: bson
56
56
  prerelease: false
57
57
  requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 7
66
+ version: 1.0.7
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
58
73
  none: false
59
74
  requirements:
60
75
  - - ~>
@@ -65,26 +80,26 @@ dependencies:
65
80
  - 0
66
81
  version: 3.0.0
67
82
  type: :runtime
68
- version_requirements: *id003
83
+ version_requirements: *id004
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: require_all
71
86
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ~>
76
91
  - !ruby/object:Gem::Version
77
92
  segments:
78
93
  - 1
79
- - 1
94
+ - 2
80
95
  - 0
81
- version: 1.1.0
96
+ version: 1.2.0
82
97
  type: :runtime
83
- version_requirements: *id004
98
+ version_requirements: *id005
84
99
  - !ruby/object:Gem::Dependency
85
100
  name: sugar-high
86
101
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
102
+ requirement: &id006 !ruby/object:Gem::Requirement
88
103
  none: false
89
104
  requirements:
90
105
  - - ~>
@@ -92,14 +107,14 @@ dependencies:
92
107
  segments:
93
108
  - 0
94
109
  - 2
95
- - 3
96
- version: 0.2.3
110
+ - 10
111
+ version: 0.2.10
97
112
  type: :runtime
98
- version_requirements: *id005
113
+ version_requirements: *id006
99
114
  - !ruby/object:Gem::Dependency
100
115
  name: roles_generic
101
116
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
117
+ requirement: &id007 !ruby/object:Gem::Requirement
103
118
  none: false
104
119
  requirements:
105
120
  - - ~>
@@ -107,10 +122,10 @@ dependencies:
107
122
  segments:
108
123
  - 0
109
124
  - 2
110
- - 2
111
- version: 0.2.2
125
+ - 7
126
+ version: 0.2.7
112
127
  type: :runtime
113
- version_requirements: *id006
128
+ version_requirements: *id007
114
129
  description: Makes it easy to set a role strategy on your User model in Mongoid
115
130
  email: kmandrup@gmail.com
116
131
  executables: []
@@ -121,9 +136,11 @@ extra_rdoc_files:
121
136
  - LICENSE
122
137
  - README.markdown
123
138
  files:
139
+ - .bundle/config
124
140
  - .document
125
141
  - .gitignore
126
142
  - .rspec
143
+ - Gemfile
127
144
  - LICENSE
128
145
  - README.markdown
129
146
  - Rakefile