playmo 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,8 +23,9 @@ end
23
23
  # forms
24
24
  # javascript_framework
25
25
  # layout
26
- # devise
27
26
  # home_controller
27
+ # devise
28
+ # cancan
28
29
  # application_helper
29
30
  # unicorn
30
31
  # thinking_sphinx
@@ -35,7 +36,7 @@ end
35
36
  # git
36
37
 
37
38
  module Playmo
38
- ROOT = File.dirname(__FILE__) + "/../"
39
+ ROOT = File.join(File.dirname(__FILE__), "..")
39
40
 
40
41
  extend ActiveSupport::Autoload
41
42
 
@@ -46,7 +47,6 @@ module Playmo
46
47
  end
47
48
  end
48
49
 
49
- autoload :Version
50
50
  autoload :Cli
51
51
  autoload :Event
52
52
  autoload :Options
@@ -52,9 +52,22 @@ module Playmo
52
52
 
53
53
  private
54
54
 
55
+ # /home/tanraya/sandbox/tanraya-playmo/lib/
55
56
  def require_gem
56
57
  return unless options[:require]
57
- require options[:require]
58
+
59
+ # Include gem as a directory for development purposes
60
+ # Just execute playmo with: playmo -r /path/to/your/awesome-gem
61
+ if options[:require].match(/^\//)
62
+ path = "#{options[:require]}/lib"
63
+
64
+ return if $LOAD_PATH.include?(path)
65
+
66
+ $LOAD_PATH.unshift(path)
67
+ require options[:require].split('/').last
68
+ else
69
+ require options[:require]
70
+ end
58
71
  end
59
72
 
60
73
  end
@@ -1,5 +1,5 @@
1
1
  module Playmo
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
 
4
4
  if ARGV.first =~ /--version|-v/
5
5
  puts VERSION
@@ -0,0 +1,90 @@
1
+ # TODO: Check is Devise installed (or make as Devise dependant)
2
+
3
+ recipe :cancan do
4
+ description 'This will add role-based authorization with CanCan'
5
+ after :devise
6
+
7
+ ask "Would you like to use CanCan in this project?" do
8
+ gem "cancan", "~> 1.6.7"
9
+
10
+ # Copy models
11
+ copy_file 'ability.rb', 'app/models/ability.rb'
12
+ copy_file 'role.rb', 'app/models/role.rb'
13
+ copy_file 'user_role.rb', 'app/models/user_role.rb'
14
+
15
+ # Create migration
16
+ filename = "db/migrate/#{(Time.now).strftime("%Y%m%d%H%M%S")}_create_role_and_user_role.rb"
17
+
18
+ create_file filename, <<-CONTENT.gsub(/^ {6}/, '')
19
+ class CreateRoleAndUserRole < ActiveRecord::Migration
20
+ def change
21
+ create_table :roles do |t|
22
+ t.string :name, :null => false
23
+ t.string :description, :null => false
24
+ end
25
+
26
+ add_index :roles, :name, :unique => true
27
+
28
+ create_table :user_roles do |t|
29
+ t.integer :role_id, :null => false
30
+ t.integer :user_id, :null => false
31
+ end
32
+
33
+ add_index :user_roles, [:role_id, :user_id], :unique => true
34
+ end
35
+ end
36
+ CONTENT
37
+
38
+ # Add associations and methods to User
39
+ install do
40
+ gsub_file 'app/models/user.rb', 'cattr_accessor :current' do
41
+ <<-CONTENT.gsub(/^ {10}/, '')
42
+ cattr_accessor :current
43
+
44
+ has_many :user_roles
45
+ has_many :roles, :through => :user_roles
46
+
47
+ # Check user role
48
+ def role?(role)
49
+ return !!self.roles.find_by_name(role.to_s.camelize)
50
+ end
51
+ CONTENT
52
+ end
53
+
54
+ gsub_file 'app/controllers/application_controller.rb', ' #when CanCan::AccessDenied' do
55
+ <<-CONTENT.gsub(/^ {8}/, '')
56
+ when CanCan::AccessDenied
57
+ if user_signed_in?
58
+ not_found
59
+ else
60
+ authenticate_user!
61
+ end
62
+ CONTENT
63
+ end
64
+
65
+ # Add roles into seeds
66
+ gsub_file 'db/seeds.rb', '# Create users' do
67
+ <<-CONTENT.gsub(/^ {10}/, '')
68
+ # Create roles
69
+ admin_role = Role.create!(:name => 'admin', :description => 'Administrator')
70
+
71
+ # Create users
72
+ CONTENT
73
+ end
74
+
75
+ gsub_file 'db/seeds.rb', 'user.save!' do
76
+ <<-CONTENT.gsub(/^ {10}/, '')
77
+ user.roles << admin_role
78
+ user.save!
79
+ CONTENT
80
+ end
81
+
82
+ gsub_file 'db/seeds.rb', 'user2.save!' do
83
+ <<-CONTENT.gsub(/^ {10}/, '')
84
+ user2.roles << admin_role
85
+ user2.save!
86
+ CONTENT
87
+ end
88
+ end
89
+ end
90
+ end
@@ -3,6 +3,6 @@ recipe :compass do
3
3
  after :application_controller
4
4
 
5
5
  ask "Would you like to use Compass in this project?" do
6
- gem "compass", "~> 0.12.alpha.0"
6
+ gem "compass", "0.12.rc.1"
7
7
  end
8
- end
8
+ end
@@ -8,7 +8,7 @@ recipe :database do
8
8
  end
9
9
 
10
10
  answer "SQLite" do
11
- store :database, :sqlite
11
+ store :database, :sqlite3
12
12
  end
13
13
  end
14
14
  end
@@ -145,7 +145,7 @@ recipe :devise do
145
145
  end
146
146
 
147
147
  # Create migration that adds name field to users table
148
- filename = "db/migrate/#{(Time.now - 3600).strftime("%Y%m%d%H%M%S")}_add_name_to_users.rb"
148
+ filename = "db/migrate/#{(Time.now).strftime("%Y%m%d%H%M%S")}_add_name_to_users.rb"
149
149
 
150
150
  create_file filename, <<-CONTENT.gsub(/^ {12}/, '')
151
151
  class AddNameToUsers < ActiveRecord::Migration
@@ -159,17 +159,21 @@ recipe :devise do
159
159
  # Create default user
160
160
  append_to_file 'db/seeds.rb' do
161
161
  <<-CONTENT.gsub(/^ {8}/, '')
162
- user = User.create!(
162
+ # Create users
163
+ user = User.new(
163
164
  :email => 'johndoe@example.com',
164
165
  :password => 'secret',
165
166
  :password_confirmation => 'secret'
166
167
  )
167
168
 
168
- user2 = User.create!(
169
+ user2 = User.new(
169
170
  :email => 'annadoe@example.com',
170
171
  :password => 'secret',
171
172
  :password_confirmation => 'secret'
172
173
  )
174
+
175
+ user.save!
176
+ user2.save!
173
177
  CONTENT
174
178
  end
175
179
 
@@ -1,6 +1,6 @@
1
1
  recipe :home_controller do
2
2
  description 'This will add HomeController into your app that present home page'
3
- after :layout
3
+ after :cancan
4
4
 
5
5
  # Make changes in index view
6
6
  def change_index_view
@@ -14,5 +14,15 @@ recipe :setup_database do
14
14
  seed_database do
15
15
  run "cd #{application_name} && rake db:seed"
16
16
  end
17
+
18
+ prepend_file 'db/seeds.rb' do
19
+ <<-CONTENT.gsub(/^ {8}/, '')
20
+ # encoding: utf-8
21
+
22
+ # Clear database
23
+ Rake::Task["db:reset"].invoke
24
+
25
+ CONTENT
26
+ end
17
27
  end
18
28
  end
@@ -17,7 +17,6 @@ protected
17
17
  def handle_exceptions(e)
18
18
  case e
19
19
  #when CanCan::AccessDenied
20
- # not_found
21
20
  when ActiveRecord::RecordNotFound
22
21
  not_found
23
22
  else
@@ -0,0 +1,20 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ user ||= User.new # guest user
6
+
7
+ if user.role?(:admin)
8
+ can :manage, :all
9
+ end
10
+
11
+ # Examples. Uncomment and change.
12
+ #if user.role?(:admin)
13
+ # can :manage, :all
14
+ #elsif user.role?(:master)
15
+ # # Master can manage only own works
16
+ # can :manage, Master, :id => user.id
17
+ # can :manage, MasterWork, :master => { :id => user.id }
18
+ #end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ class Role < ActiveRecord::Base
4
+ has_many :users, :through => :user_role
5
+
6
+ validates :name, :description, :presence => true
7
+
8
+ def to_s
9
+ name
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class UserRole < ActiveRecord::Base
4
+ belongs_to :user
5
+ belongs_to :role
6
+
7
+ validates :user_id, :presence => true, :numericality => true
8
+ validates :role_id, :presence => true, :numericality => true
9
+
10
+ def to_s
11
+ "user_id: #{user_id}, role_id: #{role_id}"
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-21 00:00:00.000000000Z
12
+ date: 2012-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &76724050 !ruby/object:Gem::Requirement
16
+ requirement: &15793700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76724050
24
+ version_requirements: *15793700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby_events
27
- requirement: &76723560 !ruby/object:Gem::Requirement
27
+ requirement: &15792840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *76723560
35
+ version_requirements: *15792840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: haml2slim
38
- requirement: &76722770 !ruby/object:Gem::Requirement
38
+ requirement: &15791260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.4.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *76722770
46
+ version_requirements: *15791260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &76721730 !ruby/object:Gem::Requirement
49
+ requirement: &15790580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.1.4
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *76721730
57
+ version_requirements: *15790580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec-rails
60
- requirement: &76720810 !ruby/object:Gem::Requirement
60
+ requirement: &15789920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - =
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 2.8.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *76720810
68
+ version_requirements: *15789920
69
69
  description:
70
70
  email:
71
71
  - demerest@gmail.com
@@ -109,7 +109,7 @@ files:
109
109
  - recipes/application_controller_recipe.rb
110
110
  - recipes/application_helper_recipe.rb
111
111
  - recipes/assets_recipe.rb
112
- - recipes/can_can_recipe.rb
112
+ - recipes/cancan_recipe.rb
113
113
  - recipes/capistrano_recipe.rb
114
114
  - recipes/compass_recipe.rb
115
115
  - recipes/database_recipe.rb
@@ -149,6 +149,9 @@ files:
149
149
  - recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_media.css.scss
150
150
  - recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_reset.css.scss
151
151
  - recipes/templates/assets_recipe/stylesheets/partials/html5-boilerplate/_styles.css.scss
152
+ - recipes/templates/cancan_recipe/ability.rb
153
+ - recipes/templates/cancan_recipe/role.rb
154
+ - recipes/templates/cancan_recipe/user_role.rb
152
155
  - recipes/templates/capistrano_recipe/.gitkeep
153
156
  - recipes/templates/capistrano_recipe/deploy.rb
154
157
  - recipes/templates/home_controller_recipe/_sidebar.html.erb
@@ -182,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
185
  version: '0'
183
186
  requirements: []
184
187
  rubyforge_project: playmo
185
- rubygems_version: 1.8.10
188
+ rubygems_version: 1.8.15
186
189
  signing_key:
187
190
  specification_version: 3
188
191
  summary: Special kit that allows you create html5-ready Rails 3 apps quick with pre-included
File without changes