Skip to content

Commit

Permalink
Added options to specify database username and password in the refine…
Browse files Browse the repository at this point in the history
…rycms installer task.
  • Loading branch information
parndt committed Dec 15, 2010
1 parent fd25e28 commit 4e94a9b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
28 changes: 23 additions & 5 deletions bin/refinerycms
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ module Refinery
# Default options
@input = input
@options = {
:database => 'sqlite3',
:database => {
:adapter => 'sqlite3',
:username => 'root',
:password => ''
},
:force => false,
:heroku => false,
:gems => []
Expand All @@ -41,7 +45,15 @@ module Refinery
# Rails supports more options, but Refinery is only tested on these three
databases = %w(mysql postgresql sqlite3)
opts.on("-d DATABASE", "--database DATABASE", databases, "Select the database (default sqlite3)", " #{databases.join('/')}") do |db|
@options[:database] = db
@options[:database][:adapter] = db
end

opts.on("-u USERNAME", '--database-username USERNAME', String, "Set the database username", ' (default root)') do |username|
@options[:database][:username] = username
end

opts.on("-p PASSWORD", '--database-password PASSWORD', String, "Set the database password", " (default '')") do |password|
@options[:database][:password] = password
end

opts.on("-g", "--gems gem1,gem2,gem3", Array, "Additional gems to install") do |gems|
Expand Down Expand Up @@ -119,7 +131,7 @@ module Refinery
def generate!
# Generate a rails application
rails_command = "rails new \"#{@app_path}\""
rails_command << " --database #{@options[:database]}"
rails_command << " --database #{@options[:database][:adapter]}"
rails_command << " --force" if @options[:force]
rails_command << " --skip-test-unit --skip-prototype"
run_command(rails_command, {:cd => false})
Expand Down Expand Up @@ -160,6 +172,10 @@ module Refinery
f.write "\n" + refinery_gems + "\n\n# USER DEFINED\n" + @options[:gems].join("\n") + "\n# END USER DEFINED"
end

# Override database username and password
find_and_replace('config/database.yml', %r{username:.*}, "username: #{@options[:database][:username]}")
find_and_replace('config/database.yml', %r{password:.*}, "password: #{@options[:database][:password]}")

# Specify the correct version of the Refinery CMS gem (may be git source).
src = Refinery.version !~ /\.pre$/ ? "'~> #{Refinery.version}'" : ":git => 'git://github.com/resolve/refinerycms.git'"
find_and_replace('Gemfile', "gem 'refinerycms', :path => '.'",
Expand Down Expand Up @@ -194,9 +210,11 @@ module Refinery
puts "Installing gem requirements using bundler..\n"
run_command("bundle install")

# sqlite3 requires we use 'db:migrate' etc instead of 'db:setup'
puts "\n\nSetting up your development database..\n"
%w(db:drop db:create db:migrate db:seed).each do |db|
run_command("rake -f \"#{@app_path.join('Rakefile')}\" #{db}")
tasks = @options[:database][:adapter] == 'sqlite3' ? %w(db:migrate db:seed) : %w(db:setup)
tasks.each do |task|
run_command("rake -f \"#{@app_path.join('Rakefile')}\" #{task}")
end

# Deploy to Heroku
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.9.8.8 [16 December 2010]
* Prevented RefinerySetting from accessing its database table before it is created. [Philip Arndt](http://github.com/parndt)
* Prevented RefinerySetting from accessing its database table before it is created. [Philip Arndt](https://github.com/parndt)
* Added more options to ``bin/refinerycms`` like ability to specify database username and password. [Philip Arndt](https://github.com/parndt)
* [See full list](https://github.com/resolve/refinerycms/compare/0.9.8.7...0.9.8.8)

## 0.9.8.7 [15 December 2010]
Expand Down
2 changes: 1 addition & 1 deletion refinerycms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.name = %q{refinerycms}
s.version = %q{0.9.8.8}
s.description = %q{A Ruby on Rails CMS that supports Rails 3. It's easy to extend and sticks to 'the Rails way' where possible.}
s.date = %q{2010-12-15}
s.date = %q{2010-12-16}
s.summary = %q{A Ruby on Rails CMS that supports Rails 3}
s.email = %q{[email protected]}
s.homepage = %q{http://refinerycms.com}
Expand Down

0 comments on commit 4e94a9b

Please sign in to comment.