cream 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,33 +1,41 @@
1
1
  # Cream
2
2
 
3
- This project aims to assist you in setting up a complete user login and role permission system for your Rails 3 app.
3
+ This project aims to assist you in setting up a complete Authentication and Authorization system for your Rails 3 app.
4
4
 
5
- It targets [Devise](http://github.com/plataformatec/devise) as the Authentication system, [CanCan](http://github.com/ryanb/cancan) with Permits and Licenses as the Authorization system and [Roles Generic](http://github.com/kristianmandrup/roles_generic) as the user Roles system.
5
+ It targets
6
+
7
+ * [Devise](http://github.com/plataformatec/devise) - Authorization
8
+ * [CanCan](http://github.com/ryanb/cancan) - Authentication
9
+ * [Roles Generic](http://github.com/kristianmandrup/roles_generic) - Roles
10
+
11
+ For more advanced Authorization configuration, cream uses cancan-permits to enabel use of Permits and Licenses.
12
+ The gems *devise-links* and *cancan-rest-links* provide view helpers to facilitate working with authentication links and model REST links with permission logic.
13
+ Cream itself provides generators to easily configure your Rails 3 app with these gems and also includes various view and controller helpers to guard view or controller logic. The project targets a collection of common ORMs for Rails, for both Relational and Document based datastores.
6
14
 
7
15
  The objective of this project is to
16
+
8
17
  * Integrate all these sub-systems
9
- * Provide a generator that can auto-configure your Rails 3 app with these sub-systems for a given ORM
18
+ * Provide generators that can auto-configure your Rails 3 app with these sub-systems for a given ORM
10
19
 
11
- ## Status
20
+ _UPDATE_: 1. Dec 2010
21
+ Finally all dependency issues have been resolved.
22
+ I have tested the 'full_config' generator in a fresh Rails 3.0.3 app and it seems to be working, at least with ORM = 'mongoid' now.
23
+ Time to check with the other ORMs as well and make fixes where needed.
12
24
 
13
- This project and the gems it assembles should all mostly work. I am currently going through all the supporting gems, making sure dependencies
14
- are updated and that they use the latest APIs of the other gems and all specs pass. Stay tuned!
15
- The config generators is currently under construction and needs some fine-tuning to bring all the gems together.
25
+ ## TODO
16
26
 
17
- I have now also started a new project called [Cream rails 3 app](http://github.com/kristianmandrup/cream-rails3-app) which is to be a template Rails 3 project
18
- that demonstrates what a final Rails 3 app using Cream will look like. I plan to use this as a template for the Cream config generator, making sure that given
19
- Mongo Mapper as the ORM and default arguments, the generartor should generate a "mirror image" of this template project. You are most welcome to help me in this effort
20
- or provide suggestions etc. The README of the template project will contain a recipe with the steps to be taken to produce it ;)
27
+ The old Demo app [Cream rails 3 app](http://github.com/kristianmandrup/cream-rails3-app) is out of date and needs to be updated!
28
+ Any help to create a Demo app is greatly appreciated.
21
29
 
22
- ### Update Nov 25, 2010
30
+ ## Status
31
+
32
+ [CanCan permits demo](https://github.com/kristianmandrup/cancan-permits-demo) is a recent Rails 3 app I created to demonstrate configuration of a Rails 3 app using
33
+ *cancan-permits* and *cancan-rest-links*. I will build on this in the near future to provide a full Rails 3 app with all the cream features enabled.
34
+ Stay tuned! Or even better, help me create such template/tutorial projects ;)
23
35
 
24
- Cream dependency to *cancan-permits* updated to use version 0.3.2.
25
- Cream Permits Config generator uses new *cancan:permits* and *cancan:licenses* generators.
36
+ ### Update Nov 28, 2010
26
37
 
27
- Currently to activate Cream in a rails app, insert this line in a Rails initializer.
28
- <code>
29
- require 'cream/configure/rails'
30
- </code>
38
+ Finally cream again installs from a clean base without any dependency problems :) I just switched to Ruby 1.9.3-dev and tested cream from a clean ruby gems.
31
39
 
32
40
  ## Authentication systems
33
41
 
@@ -39,6 +47,14 @@ Cream targets [Devise](http://github.com/plataformatec/devise) as the Authentica
39
47
 
40
48
  The project [devise links](http://github.com/kristianmandrup/devise-links) adds more convenience for creating view links to trigger Devise session actions.
41
49
 
50
+ ## Authorization system
51
+
52
+ There is support for the [CanCan](http://github.com/ryanb/cancan) Authorization system.
53
+ I have created a [Cancan permits](http://github.com/kristianmandrup/cancan-permits) gem that adds the concept of Permits for each role (see below).
54
+
55
+ _Note:_
56
+ You are most welcome to provide "plugins" for other permission frameworks!
57
+
42
58
  ## Roles
43
59
 
44
60
  I have developed a flexible *Generic Roles* strategy system.
@@ -67,26 +83,21 @@ _Update:_
67
83
  Roles Generic has recently been upgraded with a better API, architecture, framework for testing and more and better functionality. It should also now be more DRY and
68
84
  easier/simpler to add more strategies and Datastore adapters.
69
85
 
70
- ## Permission systems
71
-
72
- There is support for the [CanCan](http://github.com/ryanb/cancan) permission system.
73
- I have created a [Cancan permits](http://github.com/kristianmandrup/cancan-permits) gem that adds the concept of Permits for each role (see below).
74
-
75
- _Note:_
76
- You are most welcome to provide "plugins" for other permission frameworks!
77
-
78
86
  ## ORMs
79
87
 
80
- In general, it should now finally be pretty easy to set up a Rails 3 app, with a full Session system, Permission system linked to a Role strategy system using any ORM. Devise supports the following ORMS:
88
+ In general, it should now finally be pretty easy to set up a Rails 3 app, with a full Authentication and an Authorization system linked to a Role system using one of the following supported Cream ORMs.
81
89
 
90
+ Relational DB:
82
91
  * Active Record
83
92
  * Data Mapper
84
- * Mongo Mapper
85
- * Mongoid
93
+
94
+ Document datastores:
95
+ * Mongo DB
96
+ ** Mongo Mapper
97
+ ** Mongoid
86
98
  * Couch DB
87
99
 
88
- These ORMs are also supported for the Roles strategy system. The Permission system should not have any ORM dependency.
89
- There are plans to create a top-level generator which sets up your project with all these systems for a given ORM.
100
+ These ORMs are also supported for the CanCan Permits and Roles systems.
90
101
 
91
102
  ## Installation and configuration ##
92
103
 
@@ -97,12 +108,6 @@ This gem has been designed for Rails 3 only.
97
108
  Insert <pre>gem 'cream'</pre> in your Rails 3 Gemfile
98
109
  <pre>$ bundle install</pre>
99
110
 
100
- ### Install as plugin
101
-
102
- In the near future...
103
-
104
- <code>rails plugin install http://github.com/kristianmandrup/cream.git</code>
105
-
106
111
  ## Role system
107
112
 
108
113
  Role strategies can be set up using the [Roles Generic](http://github.com/kristianmandrup/roles_generic) gem or any of the ORM specific roles gems such as [Roles - Active Record](http://github.com/kristianmandrup/roles_active_record). There are currently Roles implementations for the following ORMs:
@@ -111,36 +116,32 @@ Role strategies can be set up using the [Roles Generic](http://github.com/kristi
111
116
  * Data Mapper
112
117
  * Mongo Mapper
113
118
  * Mongoid
114
- * Couch DB
119
+ * Couch DB (via SimplyStored)
115
120
 
116
121
  ### Update
117
122
 
118
- The Role systems for Active Record, Mongoid and MongoMapper have recently been upgraded to take advantage of the new Roles Generic API and archictecture.
119
- I hope to soon have time to also upgrade the remaining ORM Role adapters.
123
+ The Role systems all ORMs (except SimplyStored which is in progress) have recently been upgraded to take advantage of a new Roles Generic API and archictecture.
120
124
 
121
- ## Permission system
125
+ ## CanCan
122
126
 
123
- The only Permission system currently supported is *CanCan*.
127
+ Role based authorization for [CanCan](http://github.com/ryanb/cancan) can be done by creating a *Permit* class for each role.
124
128
 
125
- ### CanCan
129
+ ### Permits
126
130
 
127
- Role based authorization for [CanCan](http://github.com/ryanb/cancan) is currently done by creating *Permits* for each role.
128
131
  A *Permit* lets a user in a given role do certain actions as defined in the Permit.
132
+ A Permit can also reuse permission logic in the form of Licenses for a more fine grained design if needed.
129
133
 
130
- The *config* generator will generate a set of Permit files which are placed in '/app/permits'. You can then edit the Permits to suit your needs.
134
+ CanCan Permits comes with generators to generate Permit files which are placed in '/app/permits'. You can then edit the Permits to suit your needs.
131
135
 
132
136
  The project [CanCan REST links](http://github.com/kristianmandrup/cancan-rest-links) provides a convenient way to handle CanCan REST links, using a flexible API.
133
137
 
134
- ## Permits
135
-
136
- Currently CanCan is supported as the permission system. I have added the concept of Permits (and optionally Licenses) linked to Roles.
137
-
138
138
  Check out [Cancan permits](http://github.com/kristianmandrup/cancan-permits) for more info for how to use Permits.
139
139
 
140
- Cream has ben updated to support my the version of *Cancan permits*, which now support all the ORMs that both Cream and Roles Generic support.
140
+ *Cancan permits* support all the ORMs that both Devise and Roles Generic support.
141
+
142
+ ### Licenses
141
143
 
142
- For more advanced role/permission scenarios you can create Licenses placed in '/app/licenses/', which are 'permission sets' that can be reused across multiple Permits.
143
- Note: The gem *cancan-permits* comes with both a *permits* and a *licenses* generator.
144
+ For more advanced authorization scenarios you can create reusable permission logic in license classed that are placed in '/app/licenses/'. A License can be reused in multiple Permits.
144
145
 
145
146
  See [CanCan permits demo app](https://github.com/kristianmandrup/cancan-permits-demo) for an example of how to use cancan-permits and licenses.
146
147
 
@@ -159,20 +160,27 @@ Sub-generators
159
160
  * permits:config - Configures app with CanCan Permits
160
161
  * roles:config - Configures app with Roles
161
162
 
162
- All the above generators now have specs to show how to use them.
163
- Note: These generators have still not been tested in all scenarios with all ORMs, role strategies etc.
164
- I am sure there are still some issues... so please help uncover these!
163
+ * cancan:restlinks - create REST links locale file
164
+ * devise:links - create devise links locale file (should maybe be renamed authlinks?)
165
165
 
166
- In general, the cream:config generator can be seen as a kind of "super generator", in that it should call all the sub-generators in succession to attempt to fully configure
167
- and applicaiton in one go.
166
+ All the above generators have specs included in cream that demonstrate how to use them and should verify that they work as expected.
168
167
 
169
- Cream will support these ORMs:
168
+ In general, the cream:config generator can be seen as a kind of "super generator", in that it should call all the sub-generators in succession to fully configure
169
+ the Rails 3 app in one go. I need more people to test this out to see how well it works. I am sure there are still a few bugs and issues here...
170
170
 
171
+ Cream target these ORMs:
172
+
173
+ Relational DB (SQL)
171
174
  * Active Record
172
175
  * Data Mapper
176
+
177
+ Mongo Mapper (NoSQL Document store)
173
178
  * Mongo Mapper
174
179
  * Mongoid
175
180
 
181
+ Couch DB (NoSQL Document store)
182
+ * SimplyStored ()
183
+
176
184
  ### Config Generator ###
177
185
 
178
186
  Master cream generator which calls the sub-generators in succession.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.6
1
+ 0.7.7
data/cream.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cream}
8
- s.version = "0.7.6"
8
+ s.version = "0.7.7"
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-11-28}
12
+ s.date = %q{2010-12-01}
13
13
  s.description = %q{Provides assistance for setting up Session, Role and Permission systems for a Rails 3 app. Support for multiple ORMs}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
26
26
  "README.markdown",
27
27
  "Rakefile",
28
28
  "VERSION",
29
- "app/views/auth_assist/menu/_admin_login_items.html.erb",
30
- "app/views/auth_assist/menu/_login_items.html.erb",
31
- "app/views/auth_assist/menu/_registration_items.html.erb",
29
+ "app/views/cream/menu/_admin_login_items.html.erb",
30
+ "app/views/cream/menu/_login_items.html.erb",
31
+ "app/views/cream/menu/_registration_items.html.erb",
32
32
  "config/locales/cream.en.yml",
33
33
  "cream.gemspec",
34
34
  "features/FEATURE_NOTES.txt",
@@ -36,19 +36,21 @@ module Cancan
36
36
  def cancan_gems
37
37
  gem 'cancan'
38
38
  gem 'cancan-rest-links'
39
- bundle_install 'cancan', 'cancan-permits'
39
+ bundle_install #'cancan', 'cancan-permits'
40
40
  end
41
41
 
42
- def bundle_install *gems
43
- run "bundle install #{gems.jon(' ')}"
42
+ def bundle_install #*gems
43
+ run "bundle install" # #{gems.jon(' ')}"
44
44
  end
45
45
 
46
46
  # CanCan access denied exception handling
47
47
  def cancan_exception_handling
48
- logger.debug "Rescue exists? #{rescue_exists?}"
49
- return if rescue_exists?
50
-
51
- logger.debug "Insert rescue into application controller"
48
+ if rescue_exists?
49
+ logger.debug "CanCan rescue statement already exists"
50
+ return
51
+ end
52
+
53
+ logger.debug "Insert cancan rescue statement into application controller"
52
54
  insert_into_controller :application, :after => "ActionController::Base\n" do
53
55
  %{
54
56
  rescue_from CanCan::AccessDenied do |exception|
@@ -60,7 +62,7 @@ module Cancan
60
62
  end
61
63
 
62
64
  def rescue_exists?
63
- File.read(controller_file :application) =~ /rescue_from CanCan::AccessDenied/
65
+ !(File.read(controller_file :application) =~ /rescue_from CanCan::AccessDenied/).nil?
64
66
  end
65
67
  end
66
68
  end
@@ -65,7 +65,7 @@ module Cream
65
65
 
66
66
  def run_devise
67
67
  # rgen "devise:config --orm #{orm} --no-gems"
68
- rgen "devise:config --orm #{orm} --no-gems"
68
+ rgen "devise:config --orm #{orm}"
69
69
  rgen "devise:users --orm #{orm} #{admin_user_option} --no-gems"
70
70
  end
71
71
 
@@ -74,7 +74,7 @@ module Cream
74
74
  end
75
75
 
76
76
  def run_roles
77
- rgen "roles:config --orm #{orm} --roles #{roles.join(' ')} --strategy #{strategy} --no-gems"
77
+ rgen "roles:config --orm #{orm} --roles #{roles.join(' ')} --strategy #{strategy}"
78
78
  end
79
79
 
80
80
  def run_permits
@@ -129,16 +129,19 @@ module Cream
129
129
  options[:configure].map{|c| c.to_sym}
130
130
  end
131
131
 
132
+
132
133
  def cream_gems
133
- gem 'cream'
134
- # bundle_install
134
+ if !has_gem? :cream
135
+ gem 'cream'
136
+ # bundle_install
137
+ end
135
138
  end
136
139
 
137
140
  def cream_initializer
138
141
  create_initializer :cream do
139
142
  %Q{Cream.setup do |config|
140
- config.roles = #{sym_roles.inspect}
141
- end}
143
+ config.roles = #{sym_roles.inspect}
144
+ end}
142
145
  end
143
146
  end
144
147
 
@@ -12,11 +12,16 @@ module Devise
12
12
  # ORM to use
13
13
  class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
14
14
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
15
- class_option :gems, :type => :boolean, :default => false, :desc => "Add gems to gemfile?"
15
+ class_option :gems, :type => :boolean, :default => true, :desc => "Add gems to gemfile?"
16
16
 
17
17
  def configure_devise
18
18
  logger.add_logfile :logfile => logfile if logfile
19
- devise_gems if gems?
19
+ if gems?
20
+ devise_gems
21
+ else
22
+ say "WARNING: Not configuring devise gems for #{orm}", :yellow
23
+ end
24
+
20
25
  devise_install
21
26
  [:orm, :mailer, :protection].each{|m| send(:"#{m}_configure!", orm) }
22
27
  end
@@ -28,18 +33,6 @@ module Devise
28
33
 
29
34
  use_helpers :controller, :app, :special, :file
30
35
 
31
- def gems?
32
- options[:gems]
33
- end
34
-
35
- def logfile
36
- options[:logfile]
37
- end
38
-
39
- def orm
40
- options[:orm]
41
- end
42
-
43
36
  # rails generate ...
44
37
  def rgen command
45
38
  execute "rails g #{command}"
@@ -49,45 +42,68 @@ module Devise
49
42
  logger.debug command
50
43
  run command
51
44
  end
45
+
46
+ def devise_initializer
47
+ initializer_file(:devise)
48
+ end
49
+
50
+ def devise_initializer?
51
+ initializer_file?(:devise)
52
+ end
53
+
54
+ def devise_initializer_content
55
+ File.new(devise_initializer).read
56
+ end
52
57
 
53
- def devise_install
54
- logger.debug "initializer_file? #{initializer_file?(:devise)}"
55
- return if initializer_file?(:devise)
58
+ def devise_install
59
+ if devise_initializer?
60
+ logger.debug "initializers/devise.rb was found so devise:install will not be run"
61
+ return
62
+ end
63
+ logger.debug "initializers/devise.rb was NOT found so devise:install will now be run"
56
64
  rgen 'devise:install'
57
65
  end
58
66
 
59
- def bundle_install *gems
60
- run "bundle install #{gems.join(' ')}"
67
+ def bundle_install #*gems
68
+ # run "bundle install #{gems.join(' ')}"
69
+ run "bundle install"
61
70
  end
62
71
 
63
72
  def devise_gems
64
- logger.debug 'devise_gems'
65
- gem 'devise'
73
+ say "Configuring devise gems for #{orm}", :green
74
+ add_gem 'devise'
66
75
 
67
76
  orm_gem = nil
68
77
  # Devise ORM integration
69
78
  case orm.to_sym
70
79
  when :mongoid
71
- say "Please configure Devise for Mongoid as similar to Rails 3 example app: http://github.com/fortuity/rails3-mongoid-devise"
80
+ say "Please configure Devise for Mongoid similar to Rails 3 example app: http://github.com/fortuity/rails3-mongoid-devise"
81
+ add_gem 'mongoid', '2.0.0.beta.19'
82
+ add_gem 'bson_ext', '1.1.4'
83
+ # copy_mongoid_config
72
84
  when :mongo_mapper
73
85
  orm_gem = 'mm-devise'
74
- gem 'mm-devise'
86
+ add_gem 'mm-devise'
75
87
  when :data_mapper
76
88
  orm_gem = 'dm-devise'
77
- gem 'dm-devise'
89
+ add_gem 'dm-devise'
78
90
  when :couch_db
79
91
  orm_gem = 'devise_couch'
80
- gem 'devise_couch'
92
+ add_gem 'devise_couch'
81
93
  say "Please note that Couch DB does not currently have a Roles implementation. Feel free to provide one."
82
94
  say "Look at Roles DataMapper (roles_data_mapper) for an example ;)"
83
95
  else
84
96
  say "Orm #{orm} is not currently supported by Cream. You are most welcome to provide a Cream adapter for that ORM ;)"
85
97
  end
86
- bundle_install 'devise', orm_gem
98
+ bundle_install #'devise', orm_gem
99
+ if orm.to_sym == :mongoid
100
+ rgen 'mongoid:config'
101
+ rgen "devise mongoid"
102
+ end
87
103
  end
88
104
 
89
105
  def protection_configure! orm
90
- logger.debug "config protection"
106
+ logger.debug "Configuring: devise authentication filter"
91
107
  ## Add Devise protection to Application controller:
92
108
  insert_into_controller :application do
93
109
  "before_filter :authenticate_user!"
@@ -97,18 +113,88 @@ module Devise
97
113
  # inside 'config/initializers/devise.rb' change to:
98
114
  # require 'devise/orm/mongo_mapper'
99
115
  def orm_configure! orm
100
- return if orm == :active_record
101
- logger.debug "config orm: #{orm}"
102
- found = File.read(initializer_file(:devise)) =~/devise\/orm\/w+/
103
- logger.debug "found?: #{found}"
116
+ return if orm == 'active_record'
117
+ logger.debug "Configuring orm: [#{orm}]"
104
118
 
105
- File.replace_content_from initializer_file(:devise), :where => /devise\/orm\/\w+/, :with => "devise/orm/#{orm}"
119
+ if !devise_initializer?
120
+ say "WARNING: initializer/devise.rb not found", :yellow
121
+ return
122
+ end
123
+
124
+ if !has_statement?(orm_replacement)
125
+ logger.debug "require 'devise/orm/#{orm}' already in devise.rb initializer"
126
+ return
127
+ end
128
+
129
+ if !has_devise_orm_statement?
130
+ say "WARNING: devise/orm statement not found in devise.rb initializer", :yellow
131
+ return
132
+ end
133
+
134
+ File.replace_content_from devise_initializer, :where => orm_statement, :with => orm_replacement
106
135
  end
107
136
 
108
137
  def mailer_configure! orm
109
- logger.debug "config mailer"
138
+ logger.debug "Configuring: devise mailer"
110
139
  insert_application_config "action_mailer.default_url_options = { :host => 'localhost:3000' }"
111
140
  end
141
+
142
+ private
143
+
144
+ def add_gem_version name, version
145
+ if !has_gem_version?(name, version)
146
+ logger.debug "Adding gem: #{name}, #{version}"
147
+ gem(name, version)
148
+ else
149
+ logger.debug "gem: #{name}, #{version} already in Gemfile"
150
+ end
151
+ end
152
+
153
+ def add_gem name, version = nil
154
+ add_gem_version(name, version) and return if version
155
+ if !has_gem? name
156
+ logger.debug "Adding gem: #{name}"
157
+ gem name
158
+ else
159
+ logger.debug "gem: #{name} already in Gemfile"
160
+ end
161
+ end
162
+
163
+ # def copy_mongoid_config
164
+ # file File.dirname(__FILE__) + '/mongoid.yml', 'config/mongoid.yml'
165
+ # end
166
+
167
+ def gems?
168
+ options[:gems]
169
+ end
170
+
171
+ def logfile
172
+ options[:logfile]
173
+ end
174
+
175
+ def orm
176
+ options[:orm]
177
+ end
178
+
179
+ def has_devise_orm_statement?
180
+ devise_initializer_content =~ orm_statement
181
+ end
182
+
183
+ def has_statement? statement
184
+ devise_initializer_content =~ /#{Regexp.escape(statement)}/
185
+ end
186
+
187
+ def has_devise_orm_replacement?
188
+ has_statement? orm_replacement
189
+ end
190
+
191
+ def orm_statement
192
+ /devise\/orm\/\w+/
193
+ end
194
+
195
+ def orm_replacement
196
+ "devise/orm/#{orm}"
197
+ end
112
198
  end
113
199
  end
114
200
  end
@@ -46,11 +46,11 @@ module Devise
46
46
 
47
47
  def devise_gems
48
48
  gem 'devise'
49
- bundle_install 'devise'
49
+ bundle_install # 'devise'
50
50
  end
51
51
 
52
- def bundle_install *gems
53
- run "bundle install #{gems.jon(' ')}"
52
+ def bundle_install #*gems
53
+ run "bundle install" # #{gems.jon(' ')}"
54
54
  end
55
55
 
56
56
  def devise_default_user
@@ -61,11 +61,11 @@ module Permits
61
61
 
62
62
  def permits_gems
63
63
  gem 'cancan-permits'
64
- bundle_install 'cancan-permits'
64
+ bundle_install # 'cancan-permits'
65
65
  end
66
66
 
67
- def bundle_install *gems
68
- run "bundle install #{gems.jon(' ')}"
67
+ def bundle_install #*gems
68
+ run "bundle install" # #{gems.jon(' ')}"
69
69
  end
70
70
  end
71
71
  end
@@ -15,7 +15,7 @@ module Roles
15
15
  class_option :roles, :type => :array, :default => ['guest', 'admin'], :desc => "Valid roles to use"
16
16
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
17
17
  class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
18
- class_option :gems, :type => :boolean, :default => false, :desc => "Add gems to gemfile?"
18
+ class_option :gems, :type => :boolean, :default => true, :desc => "Add gems to gemfile?"
19
19
 
20
20
  def configure_roles
21
21
  logger.add_logfile :logfile => logfile if logfile
@@ -66,14 +66,18 @@ module Roles
66
66
  options[:default_roles]
67
67
  end
68
68
 
69
+ def add_gem name
70
+ gem name if !has_gem? name
71
+ end
72
+
69
73
  def roles_gems
70
74
  gem_name = "roles_#{orm}"
71
- gem gem_name
72
- bundle_install gem_name
75
+ add_gem gem_name
76
+ bundle_install #gem_name
73
77
  end
74
78
 
75
- def bundle_install *gems
76
- run "bundle install #{gems.join(' ')}"
79
+ def bundle_install #*gems
80
+ run "bundle install" #{gems.join(' ')}
77
81
  end
78
82
 
79
83
  def roles_generator
@@ -81,7 +85,7 @@ module Roles
81
85
  end
82
86
 
83
87
  def create_roles
84
- rgen "#{roles_generator} --strategy #{strategy} --roles #{roles} #{default_roles}"
88
+ rgen "#{roles_generator} User --strategy #{strategy} --roles #{roles} #{default_roles}"
85
89
  end
86
90
 
87
91
  def set_valid_roles_cream
@@ -91,7 +95,7 @@ module Roles
91
95
  replace_in_model_file :user, :where => /valid_roles_are\s+[(.*)]/, :with => 'valid_roles_are Cream.roles'
92
96
  else
93
97
  insert_into_model :user do
94
- "valid_roles_are Cream.roles"
98
+ "valid_roles_are Cream::Role.available"
95
99
  end
96
100
  end
97
101
  else
@@ -107,7 +111,7 @@ module Roles
107
111
  user_exist?
108
112
 
109
113
  unless read_model(:user) =~ /use_roles_strategy/
110
- inject_into_file model_file(:user), "use_roles_strategy :admin_flag\n\n", :before => "class"
114
+ inject_into_file model_file(:user), "use_roles_strategy :#{strategy}\n\n", :before => "class"
111
115
  end
112
116
  end
113
117
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 6
9
- version: 0.7.6
8
+ - 7
9
+ version: 0.7.7
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-11-28 00:00:00 +01:00
17
+ date: 2010-12-01 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -426,9 +426,9 @@ files:
426
426
  - README.markdown
427
427
  - Rakefile
428
428
  - VERSION
429
- - app/views/auth_assist/menu/_admin_login_items.html.erb
430
- - app/views/auth_assist/menu/_login_items.html.erb
431
- - app/views/auth_assist/menu/_registration_items.html.erb
429
+ - app/views/cream/menu/_admin_login_items.html.erb
430
+ - app/views/cream/menu/_login_items.html.erb
431
+ - app/views/cream/menu/_registration_items.html.erb
432
432
  - config/locales/cream.en.yml
433
433
  - cream.gemspec
434
434
  - features/FEATURE_NOTES.txt