-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial start to getting clearance working on Rails 3
- Loading branch information
Chad Pytel
committed
Jun 9, 2010
1 parent
12f3371
commit 395b589
Showing
52 changed files
with
9,213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'rails/generators/active_record' | ||
|
||
class ClearanceGenerator < ActiveRecord::Generators::Base | ||
desc "Setup the basic stuff needed for Clearance" | ||
|
||
argument :name, :type => :string, :default => "migration_source_name" | ||
|
||
def self.source_root | ||
@_clearance_source_root ||= File.expand_path("../../../../../../../../../generators/clearance/templates", __FILE__) | ||
end | ||
|
||
def install | ||
template "clearance.rb", "config/initializers/clearance.rb" | ||
|
||
inject_into_class "app/controllers/application_controller.rb", ApplicationController do | ||
" include Clearance::Authentication\n" | ||
end | ||
|
||
user_model = "app/models/user.rb" | ||
if File.exists?(user_model) | ||
inject_into_class user_model, User do | ||
"include Clearance::User" | ||
end | ||
else | ||
template "user.rb", user_model | ||
end | ||
|
||
route "Clearance::Routes.draw(map)" | ||
|
||
template "factories.rb", "test/factories/clearance.rb" | ||
|
||
migration_template "migrations/#{migration_source_name}.rb", | ||
"db/migrate/clearance_#{migration_target_name}" | ||
|
||
#readme "README" | ||
end | ||
|
||
private | ||
|
||
def schema_version_constant | ||
if upgrading_clearance_again? | ||
"To#{schema_version.gsub('_', '')}" | ||
end | ||
end | ||
|
||
def migration_source_name | ||
if ActiveRecord::Base.connection.table_exists?(:users) | ||
'update_users' | ||
else | ||
'create_users' | ||
end | ||
end | ||
|
||
def migration_target_name | ||
if upgrading_clearance_again? | ||
"update_users_to_#{schema_version}" | ||
else | ||
'create_users' | ||
end | ||
end | ||
|
||
def schema_version | ||
IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_') | ||
end | ||
|
||
def upgrading_clearance_again? | ||
ActiveRecord::Base.connection.table_exists?(:users) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.bundle | ||
db/*.sqlite3 | ||
log/*.log | ||
tmp/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'rails', '3.0.0.beta3' | ||
|
||
# Bundle edge Rails instead: | ||
# gem 'rails', :git => 'git://github.com/rails/rails.git' | ||
|
||
gem 'sqlite3-ruby', :require => 'sqlite3' | ||
|
||
gem 'mocha' | ||
|
||
gem 'formtastic', "1.0.0.beta", :git => "git://github.com/justinfrench/formtastic.git", :branch => "rails3" | ||
|
||
gem 'shoulda', '>= 2.10.3', :git => "git://github.com/thoughtbot/shoulda.git", :branch => "master" | ||
gem 'factory_girl', '>= 1.2.3', :git => "git://github.com/thoughtbot/factory_girl.git", :branch => "fixes_for_rails3" | ||
gem 'nokogiri', '1.4.1' | ||
gem 'cucumber-rails', '0.3.0' | ||
gem 'webrat', '0.7.0' | ||
|
||
# Use unicorn as the web server | ||
# gem 'unicorn' | ||
|
||
# Deploy with Capistrano | ||
# gem 'capistrano' | ||
|
||
# Bundle the extra gems: | ||
# gem 'bj' | ||
# gem 'nokogiri', '1.4.1' | ||
# gem 'sqlite3-ruby', :require => 'sqlite3' | ||
# gem 'aws-s3', :require => 'aws/s3' | ||
|
||
# Bundle gems for certain environments: | ||
# gem 'rspec', :group => :test | ||
# group :test do | ||
# gem 'webrat' | ||
# end |
Oops, something went wrong.