Class: Lono::New

Inherits:
Object
  • Object
show all
Defined in:
lib/lono/new.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ New

Returns a new instance of New.



3
4
5
6
7
# File 'lib/lono/new.rb', line 3

def initialize(options)
  @options = options
  @project_root = options[:project_root] || '.'
  @format = options[:format] || 'json'
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/lono/new.rb', line 2

def options
  @options
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lono/new.rb', line 9

def run
  puts "Setting up lono project" unless options[:quiet]
  source_root = File.expand_path("../../starter_projects/#{@format}_project", __FILE__)
  paths = Dir.glob("#{source_root}/**/*").
            select {|p| File.file?(p) }
  paths.each do |src|
    # starter_projects/yaml_project/ ->
    regexp = Regexp.new(".*starter_projects/#{@format}_project/")
    dest = src.gsub(regexp,'')
    dest = "#{@project_root}/#{dest}"

    if File.exist?(dest) and !options[:force]
      puts "already exists: #{dest}" unless options[:quiet]
    else
      puts "creating: #{dest}" unless options[:quiet]
      dirname = File.dirname(dest)
      FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
      FileUtils.cp(src, dest)
    end
  end
  puts "Starter lono project created" unless options[:quiet]
end