roles_mongo_mapper 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source :rubygems
2
+ source 'http://gems.github.com/'
3
+
4
+ group :default do
5
+ gem "mongo_mapper", '>= 0.8.4'
6
+ gem 'bson', '>= 1.1.1'
7
+ gem "activesupport", '~> 3.0.1'
8
+ gem "require_all", '~> 1.2.0'
9
+ gem "sugar-high", '>= 0.3.0'
10
+ gem "roles_generic", '>= 0.3.2'
11
+ gem 'logging_assist', '>= 0.2.0'
12
+ end
13
+
14
+ group :test do
15
+ gem "rspec", '>= 2.0.1'
16
+ gem 'generator-spec', '>= 0.7.0'
17
+ end
data/Rakefile CHANGED
@@ -8,16 +8,16 @@ begin
8
8
  gem.homepage = "http://github.com/kristianmandrup/roles_mongo_mapper"
9
9
  gem.authors = ["Kristian Mandrup"]
10
10
 
11
- gem.add_development_dependency "rspec", ">= 2.1"
12
- gem.add_development_dependency 'generator-spec', "~> 0.6.5"
11
+ gem.add_development_dependency "rspec", ">= 2.0.1"
12
+ gem.add_development_dependency 'generator-spec', ">= 0.7.0"
13
13
 
14
14
  gem.add_dependency "mongo_mapper", '>= 0.8.4'
15
- gem.add_dependency "activesupport", '~> 3.0'
15
+ gem.add_dependency "activesupport", '>= 3.0.1'
16
16
  gem.add_dependency "require_all", '~> 1.2.0'
17
- gem.add_dependency "sugar-high", '~> 0.3.0'
17
+ gem.add_dependency "sugar-high", '~> 0.3.1'
18
18
  gem.add_dependency "roles_generic", '~> 0.3.3'
19
- gem.add_dependency 'rails3_artifactor', '~> 0.3.0'
20
- gem.add_dependency 'logging_assist', '>= 0.1.5'
19
+ gem.add_dependency 'rails3_artifactor', '~> 0.3.1'
20
+ gem.add_dependency 'logging_assist', '>= 0.2.0'
21
21
 
22
22
  end
23
23
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -0,0 +1,11 @@
1
+ class String
2
+ def as_filename
3
+ self.underscore
4
+ end
5
+ end
6
+
7
+ class Symbol
8
+ def as_filename
9
+ self.to_s.underscore
10
+ end
11
+ end
@@ -1,5 +1,6 @@
1
1
  require 'rails3_artifactor'
2
2
  require 'logging_assist'
3
+ require 'generators/mongo_mapper/roles/core_ext'
3
4
 
4
5
  module MongoMapper
5
6
  module Generators
@@ -17,29 +18,31 @@ module MongoMapper
17
18
 
18
19
  class_option :logfile, :type => :string, :aliases => "-l", :default => nil, :desc => "Logfile location"
19
20
 
21
+ source_root File.dirname(__FILE__) + '/templates'
22
+
20
23
  def apply_role_strategy
21
24
  logger.add_logfile :logfile => logfile if logfile
22
25
  logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
23
26
 
24
27
  if !valid_strategy?
25
- say "Strategy '#{strategy}' is not valid. The valid strategies are: #{valid_strategies.join(', ')}", :red
28
+ logger.error "Strategy '#{strategy}' is not valid. The valid strategies are: #{valid_strategies.join(', ')}"
26
29
  return
27
30
  end
28
31
 
29
- if !has_model_file?(user_class)
30
- say "User model #{user_class} not found", :red
32
+ if !has_model_file?(user_file)
33
+ logger.error "User model #{user_class} not found"
31
34
  return
32
35
  end
33
36
 
34
- if !is_mongo_mapper_model?(user_class)
35
- say "User model #{user_class} is not a Mongo Mapper Document", :red
37
+ if !is_mongo_mapper_model?(user_file)
38
+ logger.error "User model #{user_class} is not a Mongo Mapper Document"
36
39
  return
37
40
  end
38
41
 
39
42
  begin
40
43
  logger.debug "Trying to insert roles code into #{user_class}"
41
44
 
42
- insert_into_model user_class, :after => /include MongoMapper::\w+/ do
45
+ insert_into_model user_file, :after => /include MongoMapper::\w+/ do
43
46
  insertion_text
44
47
  end
45
48
  rescue Exception => e
@@ -56,8 +59,16 @@ module MongoMapper
56
59
 
57
60
  use_orm :mongo_mapper
58
61
 
62
+ def user_file
63
+ user_class.as_filename
64
+ end
65
+
66
+ def role_file
67
+ role_class.as_filename
68
+ end
69
+
59
70
  def is_mongo_mapper_model? name
60
- read_model(name) =~ /include MongoMapper::\w+/
71
+ read_model(user_class) =~ /include MongoMapper::\w+/
61
72
  end
62
73
 
63
74
  def role_class_strategy?
@@ -76,8 +87,8 @@ module MongoMapper
76
87
 
77
88
 
78
89
  def copy_role_class
79
- logger.debug "copy_role_class: #{role_class.underscore}"
80
- template 'role.rb', "app/models/#{role_class.underscore}.rb"
90
+ logger.debug "creating role model: #{role_file}"
91
+ template 'role.rb', "app/models/#{role_file}.rb"
81
92
  end
82
93
 
83
94
  def logfile
@@ -88,6 +99,10 @@ module MongoMapper
88
99
  :mongo_mapper
89
100
  end
90
101
 
102
+ def orm_class
103
+ orm.to_s.camelize
104
+ end
105
+
91
106
  def default_roles
92
107
  [:admin, :guest]
93
108
  end
@@ -114,7 +129,7 @@ module MongoMapper
114
129
  end
115
130
 
116
131
  def strategy_options
117
- return ", :role_class => :#{role_class.to_s.underscore}" if role_class_strategy? && role_class.to_s != 'Role'
132
+ return ", :role_class => '#{role_class}'" if role_class_strategy? && role_class.to_s != 'Role'
118
133
  ''
119
134
  end
120
135
 
@@ -123,7 +138,7 @@ module MongoMapper
123
138
  end
124
139
 
125
140
  def insertion_text
126
- %Q{include Roles::#{orm.to_s.camelize}
141
+ %Q{include Roles::#{orm_class}
127
142
  #{role_strategy_statement}
128
143
  #{valid_roles_statement}}
129
144
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_mongo_mapper}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
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{2011-01-06}
12
+ s.date = %q{2011-01-10}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in MongoMapper}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,10 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ "Gemfile",
22
23
  "LICENSE",
23
24
  "README.markdown",
24
25
  "Rakefile",
25
26
  "VERSION",
27
+ "lib/generators/mongo_mapper/roles/core_ext.rb",
26
28
  "lib/generators/mongo_mapper/roles/roles_generator.rb",
27
29
  "lib/generators/mongo_mapper/roles/templates/role.rb",
28
30
  "lib/roles_mongo_mapper.rb",
@@ -86,36 +88,57 @@ Gem::Specification.new do |s|
86
88
  s.specification_version = 3
87
89
 
88
90
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
89
- s.add_development_dependency(%q<rspec>, [">= 2.1"])
90
- s.add_development_dependency(%q<generator-spec>, ["~> 0.6.5"])
91
91
  s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.8.4"])
92
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
92
+ s.add_runtime_dependency(%q<bson>, [">= 1.1.1"])
93
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.1"])
93
94
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
94
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
95
+ s.add_runtime_dependency(%q<sugar-high>, [">= 0.3.0"])
96
+ s.add_runtime_dependency(%q<roles_generic>, [">= 0.3.2"])
97
+ s.add_runtime_dependency(%q<logging_assist>, [">= 0.2.0"])
98
+ s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
99
+ s.add_development_dependency(%q<generator-spec>, [">= 0.7.0"])
100
+ s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.8.4"])
101
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
102
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
103
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.1"])
95
104
  s.add_runtime_dependency(%q<roles_generic>, ["~> 0.3.3"])
96
- s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
97
- s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.5"])
105
+ s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
106
+ s.add_runtime_dependency(%q<logging_assist>, [">= 0.2.0"])
98
107
  else
99
- s.add_dependency(%q<rspec>, [">= 2.1"])
100
- s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
101
108
  s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
102
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
109
+ s.add_dependency(%q<bson>, [">= 1.1.1"])
110
+ s.add_dependency(%q<activesupport>, ["~> 3.0.1"])
111
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
112
+ s.add_dependency(%q<sugar-high>, [">= 0.3.0"])
113
+ s.add_dependency(%q<roles_generic>, [">= 0.3.2"])
114
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
115
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
116
+ s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
117
+ s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
118
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
103
119
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
104
- s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
120
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
105
121
  s.add_dependency(%q<roles_generic>, ["~> 0.3.3"])
106
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
107
- s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
122
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
123
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
108
124
  end
109
125
  else
110
- s.add_dependency(%q<rspec>, [">= 2.1"])
111
- s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
112
126
  s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
113
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
127
+ s.add_dependency(%q<bson>, [">= 1.1.1"])
128
+ s.add_dependency(%q<activesupport>, ["~> 3.0.1"])
129
+ s.add_dependency(%q<require_all>, ["~> 1.2.0"])
130
+ s.add_dependency(%q<sugar-high>, [">= 0.3.0"])
131
+ s.add_dependency(%q<roles_generic>, [">= 0.3.2"])
132
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
133
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
134
+ s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
135
+ s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
136
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
114
137
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
115
- s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
138
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
116
139
  s.add_dependency(%q<roles_generic>, ["~> 0.3.3"])
117
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
118
- s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
140
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
141
+ s.add_dependency(%q<logging_assist>, [">= 0.2.0"])
119
142
  end
120
143
  end
121
144
 
@@ -1,5 +1,6 @@
1
1
  require 'generator_spec_helper'
2
- require_generator :mongo_mapper => :roles
2
+ require 'generators/mongo_mapper/roles/roles_generator'
3
+ # require_generator :mongo_mapper => :roles
3
4
 
4
5
  # root_dir = Rails3::Assist::Directory.rails_root
5
6
  root_dir = File.join(Rails.application.config.root_dir, 'rails')
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 2
9
- version: 0.3.2
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,42 +14,147 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-06 00:00:00 +01:00
17
+ date: 2011-01-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
22
- prerelease: false
21
+ name: mongo_mapper
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
27
  segments:
28
+ - 0
29
+ - 8
30
+ - 4
31
+ version: 0.8.4
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bson
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 1
45
+ - 1
46
+ version: 1.1.1
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: activesupport
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 3
59
+ - 0
60
+ - 1
61
+ version: 3.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: require_all
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
29
74
  - 2
75
+ - 0
76
+ version: 1.2.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: sugar-high
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ - 3
90
+ - 0
91
+ version: 0.3.0
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: roles_generic
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ - 3
105
+ - 2
106
+ version: 0.3.2
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: logging_assist
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ - 2
120
+ - 0
121
+ version: 0.2.0
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 2
134
+ - 0
30
135
  - 1
31
- version: "2.1"
136
+ version: 2.0.1
32
137
  type: :development
33
- version_requirements: *id001
138
+ prerelease: false
139
+ version_requirements: *id008
34
140
  - !ruby/object:Gem::Dependency
35
141
  name: generator-spec
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
142
+ requirement: &id009 !ruby/object:Gem::Requirement
38
143
  none: false
39
144
  requirements:
40
- - - ~>
145
+ - - ">="
41
146
  - !ruby/object:Gem::Version
42
147
  segments:
43
148
  - 0
44
- - 6
45
- - 5
46
- version: 0.6.5
149
+ - 7
150
+ - 0
151
+ version: 0.7.0
47
152
  type: :development
48
- version_requirements: *id002
153
+ prerelease: false
154
+ version_requirements: *id009
49
155
  - !ruby/object:Gem::Dependency
50
156
  name: mongo_mapper
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
157
+ requirement: &id010 !ruby/object:Gem::Requirement
53
158
  none: false
54
159
  requirements:
55
160
  - - ">="
@@ -60,25 +165,26 @@ dependencies:
60
165
  - 4
61
166
  version: 0.8.4
62
167
  type: :runtime
63
- version_requirements: *id003
168
+ prerelease: false
169
+ version_requirements: *id010
64
170
  - !ruby/object:Gem::Dependency
65
171
  name: activesupport
66
- prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
172
+ requirement: &id011 !ruby/object:Gem::Requirement
68
173
  none: false
69
174
  requirements:
70
- - - ~>
175
+ - - ">="
71
176
  - !ruby/object:Gem::Version
72
177
  segments:
73
178
  - 3
74
179
  - 0
75
- version: "3.0"
180
+ - 1
181
+ version: 3.0.1
76
182
  type: :runtime
77
- version_requirements: *id004
183
+ prerelease: false
184
+ version_requirements: *id011
78
185
  - !ruby/object:Gem::Dependency
79
186
  name: require_all
80
- prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
187
+ requirement: &id012 !ruby/object:Gem::Requirement
82
188
  none: false
83
189
  requirements:
84
190
  - - ~>
@@ -89,11 +195,11 @@ dependencies:
89
195
  - 0
90
196
  version: 1.2.0
91
197
  type: :runtime
92
- version_requirements: *id005
198
+ prerelease: false
199
+ version_requirements: *id012
93
200
  - !ruby/object:Gem::Dependency
94
201
  name: sugar-high
95
- prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
202
+ requirement: &id013 !ruby/object:Gem::Requirement
97
203
  none: false
98
204
  requirements:
99
205
  - - ~>
@@ -101,14 +207,14 @@ dependencies:
101
207
  segments:
102
208
  - 0
103
209
  - 3
104
- - 0
105
- version: 0.3.0
210
+ - 1
211
+ version: 0.3.1
106
212
  type: :runtime
107
- version_requirements: *id006
213
+ prerelease: false
214
+ version_requirements: *id013
108
215
  - !ruby/object:Gem::Dependency
109
216
  name: roles_generic
110
- prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
217
+ requirement: &id014 !ruby/object:Gem::Requirement
112
218
  none: false
113
219
  requirements:
114
220
  - - ~>
@@ -119,11 +225,11 @@ dependencies:
119
225
  - 3
120
226
  version: 0.3.3
121
227
  type: :runtime
122
- version_requirements: *id007
228
+ prerelease: false
229
+ version_requirements: *id014
123
230
  - !ruby/object:Gem::Dependency
124
231
  name: rails3_artifactor
125
- prerelease: false
126
- requirement: &id008 !ruby/object:Gem::Requirement
232
+ requirement: &id015 !ruby/object:Gem::Requirement
127
233
  none: false
128
234
  requirements:
129
235
  - - ~>
@@ -131,25 +237,26 @@ dependencies:
131
237
  segments:
132
238
  - 0
133
239
  - 3
134
- - 0
135
- version: 0.3.0
240
+ - 1
241
+ version: 0.3.1
136
242
  type: :runtime
137
- version_requirements: *id008
243
+ prerelease: false
244
+ version_requirements: *id015
138
245
  - !ruby/object:Gem::Dependency
139
246
  name: logging_assist
140
- prerelease: false
141
- requirement: &id009 !ruby/object:Gem::Requirement
247
+ requirement: &id016 !ruby/object:Gem::Requirement
142
248
  none: false
143
249
  requirements:
144
250
  - - ">="
145
251
  - !ruby/object:Gem::Version
146
252
  segments:
147
253
  - 0
148
- - 1
149
- - 5
150
- version: 0.1.5
254
+ - 2
255
+ - 0
256
+ version: 0.2.0
151
257
  type: :runtime
152
- version_requirements: *id009
258
+ prerelease: false
259
+ version_requirements: *id016
153
260
  description: Makes it easy to set a role strategy on your User model in MongoMapper
154
261
  email: kmandrup@gmail.com
155
262
  executables: []
@@ -162,10 +269,12 @@ extra_rdoc_files:
162
269
  files:
163
270
  - .document
164
271
  - .rspec
272
+ - Gemfile
165
273
  - LICENSE
166
274
  - README.markdown
167
275
  - Rakefile
168
276
  - VERSION
277
+ - lib/generators/mongo_mapper/roles/core_ext.rb
169
278
  - lib/generators/mongo_mapper/roles/roles_generator.rb
170
279
  - lib/generators/mongo_mapper/roles/templates/role.rb
171
280
  - lib/roles_mongo_mapper.rb