Permalink
Browse files

validation clean up and scm repositpry path clean up

  • Loading branch information...
1 parent 4d73672 commit 0d9ba4bf66b1dc6a50f2baeaee924f0555096bee @pinguskahn pinguskahn committed Dec 17, 2008
Showing with 13 additions and 13 deletions.
  1. +0 −1 lib/railsmachine/generators/railsmachine/templates/deploy.rb
  2. +13 −12 lib/railsmachine/recipes.rb
@@ -94,7 +94,6 @@
# SCM OPTIONS
# =============================================================================
# set :scm, :subversion # :subversion or :git
-set :repository, scm == :subversion ? "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk" : "ssh://#{user}@#{domain}#{deploy_to}/repos"
# =============================================================================
# SSH OPTIONS
@@ -18,6 +18,8 @@
set :rails_env, "production"
+ load 'config/deploy'
+
set :repository do
scm = fetch(:scm)
repos_base = "#{user}@#{domain}#{deploy_to}"
@@ -30,10 +32,10 @@
task :validate_required_variables do
- raise ArgumentError, invalid_variable_value(scm, "scm", valid_scms) unless valid?(scm, valid_scms)
- raise ArgumentError, invalid_variable_value(app_server, "app_server", valid_app_servers) unless valid?(app_server, valid_app_servers)
- raise ArgumentError, invalid_variable_value(httpd, "httpd", valid_httpds) unless valid?(httpd, valid_httpds)
- raise ArgumentError, invalid_variable_value(db_adapter, "db_adapter", valid_db_adapters) unless valid?(db_adapter, valid_db_adapters)
+ validate_option(:scm, :in => [:subversion, :git])
+ validate_option(:app_server, :in => [:mongrel, :passenger])
+ validate_option(:httpd, :in => [:apache])
+ validate_option(:db_adapter, :in => [:mysql, :postgresql, :sqlite3])
end
before :require_recipes, :validate_required_variables
@@ -233,6 +235,12 @@ def switch_to_passenger
web.restart
end
+ def validate_option(key, options = {})
+ if !(options[:in].map{|o| o.to_s } + ['']).include?(self[key].to_s)
+ raise(ArgumentError, error_msg("Invalid value '#{self[key]}' for option '#{key}' must be one of the following: '#{options[:in].join(', ')}'"))
+ end
+ end
+
def application_servlet
case app_server.to_s
when 'mongrel'
@@ -241,17 +249,10 @@ def application_servlet
passenger
end
end
-
- def invalid_variable_value(value, name, valid_options)
- error_msg("'#{value}' is not a valid :#{name}. Please set :#{name} to one of the following: #{valid_options.join(", ")}")
- end
def error_msg(msg)
banner = ''; msg.length.times { banner << "+" }
return "\n\n#{banner}\n#{msg}\n#{banner}\n\n"
end
-
- def valid?(value, collection)
- collection.collect { |i| i.to_s }.include? value.to_s
- end
+
end

0 comments on commit 0d9ba4b

Please sign in to comment.