lib/provisional/project.rb in vigetlabs-provisional-2.1.6 vs lib/provisional/project.rb in vigetlabs-provisional-2.1.7
- old
+ new
@@ -1,60 +1,66 @@
require 'active_support'
+require 'provisional'
require 'uri'
require 'yaml'
module Provisional
class Project
attr_reader :options
-
- def initialize(options)
+
+ def load_options(options)
@options = HashWithIndifferentAccess.new
if options[:config]
begin
@options = @options.merge(YAML.load_file(options[:config]))
rescue
raise ArgumentError, "could not be loaded or parsed: #{options[:config]}"
end
end
- @options = @options.merge(options.reject{|k,v| v.nil?})
-
+ @options = @options.merge(options.reject{|key, value| value.nil?})
@options[:scm] ||= 'git'
@options[:template] ||= 'viget'
+ end
- unless is_valid_url?(@options['template'])
+ def find_template_path
+ begin
+ template_is_url = [URI::HTTP, URI::HTTPS].include?(URI.parse(@options['template']).class)
+ rescue URI::InvalidURIError
+ template_is_url = false
+ end
+ unless template_is_url
if File.exist?(File.expand_path(@options['template']))
@options['template_path'] = File.expand_path(@options['template'])
else
@options['template_path'] = File.expand_path(File.join(File.dirname(__FILE__),'templates',"#{@options['template']}.rb"))
end
raise ArgumentError, "is not valid: #{@options['template']}" unless File.exist?(@options['template_path'])
else
@options['template_path'] = @options['template']
end
+ end
+ def validate_options
raise ArgumentError, "name must be specified" unless @options['name']
raise ArgumentError, "already exists: #{@options['name']}" if File.exist?(@options['name'])
raise ArgumentError, "already exists: #{@options['name']}.repo" if @options['scm'] == 'svn' && File.exist?("#{@options['name']}.repo")
begin
require "provisional/scm/#{@options['scm']}"
rescue MissingSourceFile
raise ArgumentError, "is not supported: #{@options['scm']}"
end
+ end
+ def provision
scm_class = "Provisional::SCM::#{@options['scm'].classify}".constantize
- scm = scm_class.new(@options)
- scm.init
- scm.generate_rails
- scm.checkin
+ scm_class.new(@options).provision
end
- def is_valid_url?(url)
- begin
- [URI::HTTP, URI::HTTPS].include?(URI.parse(url).class)
- rescue URI::InvalidURIError
- false
- end
+ def initialize(options)
+ load_options(options)
+ find_template_path
+ validate_options
+ provision
end
-
end
end