Class: Provisional::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/provisional/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Project

Returns a new instance of Project.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/provisional/project.rb', line 9

def initialize(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[:scm] ||= 'git'
  @options[:template] ||= 'viget'

  unless is_valid_url?(@options['template'])
    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

  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

  scm_class = "Provisional::SCM::#{@options['scm'].classify}".constantize
  scm = scm_class.new(@options)
  scm.init
  scm.generate_rails
  scm.checkin
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/provisional/project.rb', line 7

def options
  @options
end

Instance Method Details

#is_valid_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/provisional/project.rb', line 51

def is_valid_url?(url)
  begin
    [URI::HTTP, URI::HTTPS].include?(URI.parse(url).class)
  rescue URI::InvalidURIError
    false
  end
end