roles_data_mapper 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -27,23 +27,29 @@ This gem is based on Jeweler, so simply:
27
27
 
28
28
  ## Rails generator
29
29
 
30
- _Note_:
31
-
32
- *The Rails generator is a bit "rusty" and hasn't been tested with the latest changes. I hope to update it soon.*
33
-
34
30
  The library comes with a Rails 3 generator that lets you populate a user model with a given role strategy
35
31
  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.
36
32
 
37
33
  * admin_flag
38
- * inline_role
39
- * inline_roles
40
- * role_relations
41
- * role_mask
34
+ * many_roles
35
+ * one_role
36
+ * roles_mask
37
+ * role_string
42
38
 
43
- Example:
39
+ *Roles generator*
40
+
41
+ Apply :admin_flag Role strategy to User model using default roles :admin and :guest (default)
44
42
 
45
43
  <code>$ rails g data_mapper:roles User --strategy admin_flag</code>
46
44
 
45
+ Apply :admin_flag Role strategy to User model using default roles and extra role :author
46
+
47
+ <code>$ rails g data_mapper:roles_migration User --strategy admin_flag --roles author</code>
48
+
49
+ Apply :one_role Role strategy to User model without default roles, only with roles :user, :special and :editor
50
+
51
+ <code>$ rails g data_mapper:roles_migration User --strategy one_role --roles user special editor --no-default-roles</code>
52
+
47
53
  ## Note on Patches/Pull Requests
48
54
 
49
55
  * Fork the project.
data/Rakefile CHANGED
@@ -7,16 +7,16 @@ begin
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/roles_for_dm"
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
12
  gem.add_dependency "dm-core", "~> 1.0"
13
13
  gem.add_dependency "dm-types", "~> 1.0"
14
14
  gem.add_dependency "dm-migrations", "~> 1.0"
15
15
 
16
- gem.add_dependency "activesupport", "~> 3.0.0"
17
- gem.add_dependency "require_all", '~> 1.1.0'
18
- gem.add_dependency "sugar-high", '~> 0.2.3'
19
- gem.add_dependency "roles_generic", '~> 0.2.2'
16
+ gem.add_dependency "activesupport", "~> 3.0.0"
17
+ gem.add_dependency "require_all", '~> 1.2.0'
18
+ gem.add_dependency "sugar-high", '~> 0.2.11'
19
+ gem.add_dependency "roles_generic", '~> 0.2.7'
20
20
 
21
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
22
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -53,9 +53,11 @@ module RoleStrategy::DataMapper
53
53
  end
54
54
 
55
55
  # assign roles
56
- def roles=(*roles)
57
- raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
58
- role_relations = role_class.find_roles(*roles)
56
+ def roles=(*_roles)
57
+ _roles = get_roles(_roles)
58
+ return nil if roles.none?
59
+
60
+ role_relations = role_class.find_roles(_roles)
59
61
  self.send("#{role_attribute}=", role_relations)
60
62
  self.save
61
63
  end
@@ -36,10 +36,11 @@ module RoleStrategy::DataMapper
36
36
 
37
37
  module Implementation
38
38
  # assign roles
39
- def roles=(*roles)
40
- raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
41
- first_role = roles.flatten.first
42
- role_relation = role_class.find_role(first_role)
39
+ def roles=(*_roles)
40
+ return nil if _roles.none?
41
+ _roles = get_roles(_roles)
42
+
43
+ role_relation = role_class.find_role(_roles.first)
43
44
  self.send("#{role_attribute}=", role_relation)
44
45
  save
45
46
  end
@@ -47,13 +48,10 @@ module RoleStrategy::DataMapper
47
48
 
48
49
  # query assigned roles
49
50
  def roles
50
- role = self.send(role_attribute).name.to_sym
51
- [role]
51
+ role = self.send(role_attribute)
52
+ role ? [role.name.to_sym] : []
52
53
  end
53
-
54
- def roles_list
55
- self.roles.to_a
56
- end
54
+ alias_method :roles_list, :roles
57
55
  end
58
56
 
59
57
  extend Roles::Generic::User::Configuration
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_data_mapper}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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-12}
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 DataMapper}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -67,33 +67,33 @@ Gem::Specification.new do |s|
67
67
  s.specification_version = 3
68
68
 
69
69
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
70
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
71
71
  s.add_runtime_dependency(%q<dm-core>, ["~> 1.0"])
72
72
  s.add_runtime_dependency(%q<dm-types>, ["~> 1.0"])
73
73
  s.add_runtime_dependency(%q<dm-migrations>, ["~> 1.0"])
74
74
  s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
75
- s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
76
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.3"])
77
- s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.2"])
75
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
76
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.11"])
77
+ s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.7"])
78
78
  else
79
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
79
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
80
80
  s.add_dependency(%q<dm-core>, ["~> 1.0"])
81
81
  s.add_dependency(%q<dm-types>, ["~> 1.0"])
82
82
  s.add_dependency(%q<dm-migrations>, ["~> 1.0"])
83
83
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
84
- s.add_dependency(%q<require_all>, ["~> 1.1.0"])
85
- s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
86
- s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
84
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
85
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
86
+ s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
87
87
  end
88
88
  else
89
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
89
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
90
90
  s.add_dependency(%q<dm-core>, ["~> 1.0"])
91
91
  s.add_dependency(%q<dm-types>, ["~> 1.0"])
92
92
  s.add_dependency(%q<dm-migrations>, ["~> 1.0"])
93
93
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
94
- s.add_dependency(%q<require_all>, ["~> 1.1.0"])
95
- s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
96
- s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
94
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
95
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
96
+ s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
97
97
  end
98
98
  end
99
99
 
@@ -1,5 +1,4 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
1
+ require 'rspec/core'
3
2
  require 'rails3_artifactor'
4
3
  require 'generator-spec'
5
4
  require 'roles_generic'
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
1
+ require 'rspec/core'
3
2
  require 'dm-core'
4
3
  require 'dm-types'
5
4
  require 'dm-migrations'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
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-12 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
@@ -23,15 +23,15 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
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
@@ -101,9 +101,9 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  segments:
103
103
  - 1
104
- - 1
104
+ - 2
105
105
  - 0
106
- version: 1.1.0
106
+ version: 1.2.0
107
107
  type: :runtime
108
108
  version_requirements: *id006
109
109
  - !ruby/object:Gem::Dependency
@@ -117,8 +117,8 @@ dependencies:
117
117
  segments:
118
118
  - 0
119
119
  - 2
120
- - 3
121
- version: 0.2.3
120
+ - 11
121
+ version: 0.2.11
122
122
  type: :runtime
123
123
  version_requirements: *id007
124
124
  - !ruby/object:Gem::Dependency
@@ -132,8 +132,8 @@ dependencies:
132
132
  segments:
133
133
  - 0
134
134
  - 2
135
- - 2
136
- version: 0.2.2
135
+ - 7
136
+ version: 0.2.7
137
137
  type: :runtime
138
138
  version_requirements: *id008
139
139
  description: Makes it easy to set a role strategy on your User model in DataMapper