cream 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Rakefile +3 -3
  2. data/VERSION +1 -1
  3. data/cream.gemspec +15 -37
  4. data/lib/cream.rb +3 -1
  5. data/lib/cream/configure/after_init/role_config.rb +19 -15
  6. data/lib/cream/configure/rails.rb +4 -12
  7. data/lib/cream/role.rb +9 -1
  8. data/lib/cream/{configure.rb → roles_config.rb} +0 -4
  9. data/lib/generators/cancan/config/config_generator.rb +13 -3
  10. data/lib/generators/cream/app/app_generator.rb +39 -18
  11. data/lib/generators/cream/full_config/full_config_generator.rb +154 -0
  12. data/lib/generators/cream/views/haml_util.rb +1 -1
  13. data/lib/generators/cream/views/views_generator.rb +1 -1
  14. data/lib/generators/devise/config/config_generator.rb +16 -7
  15. data/lib/generators/devise/users/users_generator.rb +13 -8
  16. data/lib/generators/permits/config/config_generator.rb +14 -11
  17. data/lib/generators/roles/config/config_generator.rb +12 -6
  18. data/spec/generator_spec_helper.rb +1 -1
  19. data/spec/generators/cancan/config/cancan_config_generator_spec.rb +1 -1
  20. data/spec/generators/cream/app/app_generator_spec.rb +42 -22
  21. data/spec/generators/cream/full_config/full_config_generator_spec.rb +37 -0
  22. data/spec/generators/permits/config/permits_config_generator_spec.rb +1 -1
  23. metadata +12 -35
  24. data/lib/generators/cream/config/DESIGN NOTES.markdown +0 -79
  25. data/lib/generators/cream/config/config_generator.rb +0 -86
  26. data/lib/generators/cream/config/modules/app_config.rb +0 -48
  27. data/lib/generators/cream/config/modules/cancan_config.rb +0 -27
  28. data/lib/generators/cream/config/modules/cream_config.rb +0 -36
  29. data/lib/generators/cream/config/modules/devise_config.rb +0 -58
  30. data/lib/generators/cream/config/modules/devise_users_config.rb +0 -109
  31. data/lib/generators/cream/config/modules/helper.rb +0 -79
  32. data/lib/generators/cream/config/modules/permits_config.rb +0 -15
  33. data/lib/generators/cream/config/modules/roles_config.rb +0 -39
  34. data/spec/generators/cream/config/CONFIG_GENERATOR_SPEC.markdown +0 -15
  35. data/spec/generators/cream/config/devise/existing_devise_users.rb +0 -61
  36. data/spec/generators/cream/config/empty_app/default_args_spec.rb +0 -51
  37. data/spec/generators/cream/config/permits/existing_permits_spec.rb +0 -0
  38. data/spec/generators/cream/config/permits/no_permits_spec.rb +0 -0
  39. data/spec/generators/cream/config/roles/default_roles.rb +0 -51
  40. data/spec/generators/cream/config/roles/roles_spec.rb +0 -60
  41. data/spec/generators/cream/shared_examples.rb +0 -18
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.homepage = "http://github.com/kristianmandrup/devise-assistant"
9
9
  gem.authors = ["Kristian Mandrup"]
10
10
 
11
- gem.add_development_dependency "rspec", ">= 2.0.0.rc"
11
+ gem.add_development_dependency "rspec", ">= 2.0.0"
12
12
  gem.add_development_dependency "generator-spec", "~> 0.6.5"
13
13
  gem.add_development_dependency "rspec-action_view", "~> 0.3.1"
14
14
  gem.add_development_dependency "rails-app-spec", "~> 0.2.14"
@@ -23,11 +23,11 @@ begin
23
23
  gem.add_dependency "cancan", "~> 1.4.0"
24
24
  gem.add_dependency "rails", "~> 3.0.0"
25
25
 
26
- gem.add_dependency "rails3_artifactor", "~> 0.2.5"
26
+ gem.add_dependency "rails3_artifactor", "~> 0.2.8"
27
27
  gem.add_dependency 'logging_assist', "~> 0.1.3"
28
28
 
29
29
  gem.add_dependency "r3_plugin_toolbox", "~> 0.3.6"
30
- gem.add_dependency "sugar-high", "~> 0.2.10"
30
+ gem.add_dependency "sugar-high", "~> 0.2.11"
31
31
 
32
32
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
33
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cream}
8
- s.version = "0.7.0"
8
+ s.version = "0.7.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-10-16}
12
+ s.date = %q{2010-10-17}
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 = [
@@ -38,7 +38,6 @@ Gem::Specification.new do |s|
38
38
  "features/role_strategy/clears_role_strategy.feature",
39
39
  "init.rb",
40
40
  "lib/cream.rb",
41
- "lib/cream/configure.rb",
42
41
  "lib/cream/configure/after_init/role_config.rb",
43
42
  "lib/cream/configure/rails.rb",
44
43
  "lib/cream/controller/ability.rb",
@@ -48,21 +47,13 @@ Gem::Specification.new do |s|
48
47
  "lib/cream/namespaces.rb",
49
48
  "lib/cream/rails/config.rb",
50
49
  "lib/cream/role.rb",
50
+ "lib/cream/roles_config.rb",
51
51
  "lib/cream/view/host_area.rb",
52
52
  "lib/cream/view/role_area.rb",
53
53
  "lib/cream/view/user_action_menu.rb",
54
54
  "lib/generators/cancan/config/config_generator.rb",
55
55
  "lib/generators/cream/app/app_generator.rb",
56
- "lib/generators/cream/config/DESIGN NOTES.markdown",
57
- "lib/generators/cream/config/config_generator.rb",
58
- "lib/generators/cream/config/modules/app_config.rb",
59
- "lib/generators/cream/config/modules/cancan_config.rb",
60
- "lib/generators/cream/config/modules/cream_config.rb",
61
- "lib/generators/cream/config/modules/devise_config.rb",
62
- "lib/generators/cream/config/modules/devise_users_config.rb",
63
- "lib/generators/cream/config/modules/helper.rb",
64
- "lib/generators/cream/config/modules/permits_config.rb",
65
- "lib/generators/cream/config/modules/roles_config.rb",
56
+ "lib/generators/cream/full_config/full_config_generator.rb",
66
57
  "lib/generators/cream/views/haml_util.rb",
67
58
  "lib/generators/cream/views/views_generator.rb",
68
59
  "lib/generators/cream_refactor.rb",
@@ -84,14 +75,7 @@ Gem::Specification.new do |s|
84
75
  "spec/generator_spec_helper.rb",
85
76
  "spec/generators/cancan/config/cancan_config_generator_spec.rb",
86
77
  "spec/generators/cream/app/app_generator_spec.rb",
87
- "spec/generators/cream/config/CONFIG_GENERATOR_SPEC.markdown",
88
- "spec/generators/cream/config/devise/existing_devise_users.rb",
89
- "spec/generators/cream/config/empty_app/default_args_spec.rb",
90
- "spec/generators/cream/config/permits/existing_permits_spec.rb",
91
- "spec/generators/cream/config/permits/no_permits_spec.rb",
92
- "spec/generators/cream/config/roles/default_roles.rb",
93
- "spec/generators/cream/config/roles/roles_spec.rb",
94
- "spec/generators/cream/shared_examples.rb",
78
+ "spec/generators/cream/full_config/full_config_generator_spec.rb",
95
79
  "spec/generators/cream/views_generator_spec.rb",
96
80
  "spec/generators/devise/config/devise_config_generator_spec.rb",
97
81
  "spec/generators/devise/users/devise_users_generator_spec.rb",
@@ -125,13 +109,7 @@ Gem::Specification.new do |s|
125
109
  "spec/generator_spec_helper.rb",
126
110
  "spec/generators/cancan/config/cancan_config_generator_spec.rb",
127
111
  "spec/generators/cream/app/app_generator_spec.rb",
128
- "spec/generators/cream/config/devise/existing_devise_users.rb",
129
- "spec/generators/cream/config/empty_app/default_args_spec.rb",
130
- "spec/generators/cream/config/permits/existing_permits_spec.rb",
131
- "spec/generators/cream/config/permits/no_permits_spec.rb",
132
- "spec/generators/cream/config/roles/default_roles.rb",
133
- "spec/generators/cream/config/roles/roles_spec.rb",
134
- "spec/generators/cream/shared_examples.rb",
112
+ "spec/generators/cream/full_config/full_config_generator_spec.rb",
135
113
  "spec/generators/cream/views_generator_spec.rb",
136
114
  "spec/generators/devise/config/devise_config_generator_spec.rb",
137
115
  "spec/generators/devise/users/devise_users_generator_spec.rb",
@@ -145,7 +123,7 @@ Gem::Specification.new do |s|
145
123
  s.specification_version = 3
146
124
 
147
125
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
148
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.rc"])
126
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
149
127
  s.add_development_dependency(%q<generator-spec>, ["~> 0.6.5"])
150
128
  s.add_development_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
151
129
  s.add_development_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
@@ -156,12 +134,12 @@ Gem::Specification.new do |s|
156
134
  s.add_runtime_dependency(%q<devise>, [">= 1.1.2"])
157
135
  s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
158
136
  s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
159
- s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
137
+ s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.2.8"])
160
138
  s.add_runtime_dependency(%q<logging_assist>, ["~> 0.1.3"])
161
139
  s.add_runtime_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
162
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.10"])
140
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.11"])
163
141
  else
164
- s.add_dependency(%q<rspec>, [">= 2.0.0.rc"])
142
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
165
143
  s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
166
144
  s.add_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
167
145
  s.add_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
@@ -172,13 +150,13 @@ Gem::Specification.new do |s|
172
150
  s.add_dependency(%q<devise>, [">= 1.1.2"])
173
151
  s.add_dependency(%q<cancan>, ["~> 1.4.0"])
174
152
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
175
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
153
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.8"])
176
154
  s.add_dependency(%q<logging_assist>, ["~> 0.1.3"])
177
155
  s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
178
- s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
156
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
179
157
  end
180
158
  else
181
- s.add_dependency(%q<rspec>, [">= 2.0.0.rc"])
159
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
182
160
  s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
183
161
  s.add_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
184
162
  s.add_dependency(%q<rails-app-spec>, ["~> 0.2.14"])
@@ -189,10 +167,10 @@ Gem::Specification.new do |s|
189
167
  s.add_dependency(%q<devise>, [">= 1.1.2"])
190
168
  s.add_dependency(%q<cancan>, ["~> 1.4.0"])
191
169
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
192
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.5"])
170
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.8"])
193
171
  s.add_dependency(%q<logging_assist>, ["~> 0.1.3"])
194
172
  s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
195
- s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
173
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
196
174
  end
197
175
  end
198
176
 
@@ -14,10 +14,12 @@ require 'sugar-high/kind_of'
14
14
  require 'sugar-high/array'
15
15
 
16
16
  require 'cream/role'
17
+
17
18
  require_all File.dirname(__FILE__) + '/cream/controller'
18
19
  require_all File.dirname(__FILE__) + '/cream/helper'
19
20
  require_all File.dirname(__FILE__) + '/cream/view'
20
21
  require_all File.dirname(__FILE__) + '/cream/rails'
21
22
 
22
- require 'cream/configure'
23
+ require 'cream/roles_config'
24
+
23
25
 
@@ -1,16 +1,18 @@
1
1
  module Cream::View
2
2
  module Role
3
3
  # admin?, guest? ...
4
- Cream::Role.available.each do |role|
5
- class_eval %{
6
- def #{role}_area &block
7
- area_for_roles(#{role}, &block)
8
- end
4
+ if defined? Cream::Role
5
+ Cream::Role.available.each do |role|
6
+ class_eval %{
7
+ def #{role}_area &block
8
+ area_for_roles(#{role}, &block)
9
+ end
9
10
 
10
- def for_#{role}(&block)
11
- for_roles(#{role}, &block)
12
- end
13
- }
11
+ def for_#{role}(&block)
12
+ for_roles(#{role}, &block)
13
+ end
14
+ }
15
+ end
14
16
  end
15
17
  end
16
18
  end
@@ -18,12 +20,14 @@ end
18
20
  module Cream::Helper
19
21
  module Role
20
22
  # admin?, guest? ...
21
- Cream::Role.available.each do |role|
22
- class_eval %{
23
- def #{role}?
24
- has_role? :#{role}
25
- end
26
- }
23
+ if defined? Cream::Role
24
+ Cream::Role.available.each do |role|
25
+ class_eval %{
26
+ def #{role}?
27
+ has_role? :#{role}
28
+ end
29
+ }
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -19,16 +19,8 @@ Rails3::Plugin::Extender.new do
19
19
  after :initialize do
20
20
  require_all File.dirname(__FILE__) + '/after_init'
21
21
 
22
- # Rails3.with_configuration do
23
- # autoload_paths += %W(#{Rails.root}/app/permits)
24
- # load_paths += %W( #{RAILS_ROOT}/extras )
25
- # end
26
-
27
- ActiveSupport::Dependencies.load_paths << %W(#{Rails.root}/app/permits)
28
-
29
- # set cream config object
30
- # Rails3.with_configuration do
31
- # cream = Cream::Rails::Config.new :roles => Cream::Role.available
32
- # end
33
- end
22
+ Rails3.with_configuration do
23
+ load_paths += %W(#{Rails.root}/app/permits)
24
+ end
25
+ end
34
26
  end
@@ -6,10 +6,18 @@ module Cream
6
6
  module Role
7
7
  def self.available
8
8
  return Cream.available_roles if Cream.available_roles.present?
9
+ return Cream.roles if Cream.roles.present?
9
10
  if defined? ::Role
10
11
  ::Role.all.map(&:name).to_symbols
12
+ elsif defined? ::User
13
+ ::User.roles.to_symbols
11
14
  else
12
- User.roles.to_symbols
15
+ raise %q{Available roles could not be determined. Please do either of the following:\n
16
+ 1) Create a Cream.setup block
17
+ 2) Set Cream.available_roles explicitly
18
+ 3) Create Role instances and ensure a call to Role.all returns them
19
+ 4) Set User.roles explicitly
20
+ }
13
21
  end
14
22
  end
15
23
  end
@@ -1,7 +1,3 @@
1
- require 'require_all'
2
- require 'cream/namespaces'
3
- require 'cream/configure/rails'
4
-
5
1
  module Cream
6
2
  mattr_accessor :roles
7
3
  @@roles = []
@@ -4,16 +4,17 @@ require 'cream'
4
4
  require 'rails3_artifactor'
5
5
  require 'logging_assist'
6
6
 
7
- module CanCan
7
+ module Cancan
8
8
  module Generators
9
9
  class ConfigGenerator < Rails::Generators::Base
10
10
  desc "Configure CanCan"
11
11
 
12
- class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
12
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
13
+ class_option :gems, :type => :boolean, :default => false, :desc => "Add gems to gemfile?"
13
14
 
14
15
  def cancan_configure
15
16
  logger.add_logfile :logfile => logfile if logfile
16
- cancan_gems
17
+ cancan_gems if gems?
17
18
  cancan_exception_handling
18
19
  end
19
20
 
@@ -24,6 +25,10 @@ module CanCan
24
25
 
25
26
  use_helpers :controller, :app
26
27
 
28
+ def gems?
29
+ options[:gems]
30
+ end
31
+
27
32
  def logfile
28
33
  options[:logfile]
29
34
  end
@@ -31,6 +36,11 @@ module CanCan
31
36
  def cancan_gems
32
37
  gem 'cancan'
33
38
  gem 'cancan-rest-links'
39
+ bundle_install 'cancan', 'cancan-permits'
40
+ end
41
+
42
+ def bundle_install *gems
43
+ run "bundle install #{gems.jon(' ')}"
34
44
  end
35
45
 
36
46
  # CanCan access denied exception handling
@@ -4,19 +4,17 @@ require 'cream'
4
4
  require 'rails3_artifactor'
5
5
  require 'logging_assist'
6
6
 
7
- module Roles
7
+ module Cream
8
8
  module Generators
9
- class ConfigGenerator < Rails::Generators::Base
10
- extend Rails3::Assist::UseMacro
11
-
12
- desc "Configure Permits"
9
+ class AppGenerator < ::Rails::Generators::Base
10
+ desc "Configure Cream App"
13
11
 
14
12
  # ORM to use
15
- class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
16
-
17
- class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
13
+ class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
14
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
18
15
 
19
16
  def configure_application
17
+ logger.add_logfile :logfile => logfile if logfile
20
18
  app_orm
21
19
  app_routes
22
20
  app_layout
@@ -24,39 +22,62 @@ module Roles
24
22
 
25
23
  protected
26
24
 
25
+ include Rails3::Assist::BasicLogger
26
+ extend Rails3::Assist::UseMacro
27
+ use_helpers :app, :special, :file, :view
28
+
29
+ def logfile
30
+ options[:logfile]
31
+ end
32
+
33
+ def orm
34
+ options[:orm]
35
+ end
36
+
37
+ # rails generate ...
38
+ def rgen command
39
+ execute "rails g #{command}"
40
+ end
41
+
42
+ def execute command
43
+ logger.debug command
44
+ run command
45
+ end
46
+
27
47
  def app_orm
28
48
  return if orm == 'active_record'
29
- File.replace_content_from config_file(:application), :where => "require 'rails/all'" do
49
+ File.replace_content_from application_file, :where => "require 'rails/all'" do
30
50
  %q{
31
51
  require "action_controller/railtie"
32
52
  require "action_mailer/railtie"
33
53
  require "active_resource/railtie"
34
54
  require "rails/test_unit/railtie"
35
55
  }
56
+ end
36
57
  end
37
58
 
38
59
  def app_routes
39
- routes = read_from config_file(:routes)
60
+ routes = read_routes_file
40
61
  # if no :welcome controller
41
62
  if !(routes =~ /root\s+:/)
42
63
  # create one with an 'index' view.
43
- insert_into config_file(:routes) :after => 'do', :content => 'root :to => "welcome#index"'
44
- execute "rails g controller Welcome index"
64
+ File.insert_into routes_file, :after => 'do', :content => 'root :to => "welcome#index"'
65
+ rgen "controller Welcome index"
45
66
  end
46
67
  end
47
68
 
48
69
  # in 'app/views/layouts/application.html.erb'
49
70
  # insert special flash msg displayers after opening <body> element
50
71
  def app_layout
51
- layout_content = read_view :application, :folder => 'layouts' #, :type => :erb
52
-
53
- [:alert, :notice].each{|name| insert_flash_displayer name}
72
+ layout_content = read_view :layouts => :application
73
+ [:alert, :notice].each{|name| insert_flash_displayer name, layout_content}
54
74
  end
55
75
 
56
- def insert_flash_displayer name
76
+ def insert_flash_displayer name, layout_content
57
77
  return if layout_content =~ /<%=\s+#{name}\s+%>/
58
- insert_into_view :application, :folder => 'layouts', :after => '<body>' do
59
- '<p class="alert"><%= alert %></p>'
78
+ logger.debug "insert_flash_displayer: #{name}"
79
+ insert_into_view :layouts => :application, :after => '<body>' do
80
+ %Q{<p class="#{name}"><%= #{name} %></p>}
60
81
  end
61
82
  end
62
83
  end
@@ -0,0 +1,154 @@
1
+ require 'sugar-high/file'
2
+ require 'sugar-high/module'
3
+ require 'cream'
4
+ require 'rails3_artifactor'
5
+ require 'logging_assist'
6
+
7
+ module Cream
8
+ module Generators
9
+ class FullConfigGenerator < ::Rails::Generators::Base
10
+ desc "Configures a Rails 3 app with Cream"
11
+
12
+ # Role Strategy
13
+ class_option :strategy, :type => :string, :default => 'role_string', :desc => "Role strategy to use"
14
+
15
+ # Create Admin user
16
+ class_option :admin_user, :type => :boolean, :default => false, :desc => "Create admin user"
17
+
18
+ # Roles
19
+ class_option :default_roles, :type => :boolean, :default => true, :desc => "Create default roles :admin and :guest"
20
+ class_option :roles, :type => :array, :default => [], :desc => "Roles to create"
21
+
22
+ # ORM to use
23
+ class_option :orm, :type => :string, :default => 'active_record', :desc => "ORM to use"
24
+
25
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
26
+
27
+ class_option :configure, :type => :array, :default => [], :desc => "Which generators to run"
28
+ class_option :gems, :type => :boolean, :default => true, :desc => "Add gems to gemfile?"
29
+
30
+ def main_flow
31
+ cream_initializer
32
+ cream_gems if gems?
33
+ run_generators
34
+ end
35
+
36
+ # -----------------
37
+ protected
38
+
39
+ include Rails3::Assist::BasicLogger
40
+ extend Rails3::Assist::UseMacro
41
+
42
+ use_helpers :app, :special, :file
43
+
44
+ def logfile
45
+ options[:logfile]
46
+ end
47
+
48
+ def gems?
49
+ options[:gems]
50
+ end
51
+
52
+ def run_generators
53
+ # after setting up all gems so other generators are available
54
+ # run those generators to do the heavy lifting!
55
+ run_app if configures.include? :app
56
+ run_devise if configures.include? :devise
57
+ run_cancan if configures.include? :cancan
58
+ run_roles if configures.include? :roles
59
+ run_permits if configures.include? :permits
60
+ end
61
+
62
+ def run_app
63
+ rgen "cream:app --orm #{orm}"
64
+ end
65
+
66
+ def run_devise
67
+ # rgen "devise:config --orm #{orm} --no-gems"
68
+ rgen "devise:config --orm #{orm} --no-gems"
69
+ rgen "devise:users --orm #{orm} #{admin_user_option} --no-gems"
70
+ end
71
+
72
+ def run_cancan
73
+ rgen "cancan:config --orm #{orm} --no-gems"
74
+ end
75
+
76
+ def run_roles
77
+ rgen "roles:config --orm #{orm} --roles #{roles.join(' ')} --strategy #{strategy} --no-gems"
78
+ end
79
+
80
+ def run_permits
81
+ rgen "permits:config --orm #{orm} --roles #{roles.join(' ')} --no-gems"
82
+ end
83
+
84
+ def admin_user_option
85
+ admin_user? ? '--admin-user' : ''
86
+ end
87
+
88
+ def strategy
89
+ options[:strategy]
90
+ end
91
+
92
+ def admin_user?
93
+ options[:admin_user]
94
+ end
95
+
96
+ def orm
97
+ options[:orm]
98
+ end
99
+
100
+ def default_roles?
101
+ options[:default_roles]
102
+ end
103
+
104
+ def roles
105
+ defaults = default_roles? ? ['guest', 'admin'] : []
106
+ options[:roles] + defaults
107
+ end
108
+
109
+ def sym_roles
110
+ roles.map(&:to_sym)
111
+ end
112
+
113
+ # rails generate ...
114
+ def rgen command
115
+ execute "rails g #{command}"
116
+ end
117
+
118
+ def execute command
119
+ logger.debug command
120
+ run command
121
+ end
122
+
123
+ def bundle_install
124
+ run "bundle install"
125
+ end
126
+
127
+ def configures
128
+ return [:app, :permits, :roles, :devise, :cancan] if options[:configure].empty?
129
+ options[:configure].map{|c| c.to_sym}
130
+ end
131
+
132
+ def cream_gems
133
+ gem 'cream'
134
+ # bundle_install
135
+ end
136
+
137
+ def cream_initializer
138
+ create_initializer :cream do
139
+ %Q{Cream.setup do |config|
140
+ config.roles = #{sym_roles.inspect}
141
+ end}
142
+ end
143
+ end
144
+
145
+ def cream_locale
146
+ src = File.expand_path "config/locales/en.yml".path.up(2)
147
+ # src = "config/locales/en.yml"
148
+ logger.debug "configure_locale, copy from: #{src}"
149
+ copy_file src, "config/locales/cream.en.yml"
150
+ end
151
+ end
152
+ end
153
+ end
154
+