Class: Miso::Commands::New

Inherits:
Object
  • Object
show all
Defined in:
lib/miso/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ New

Returns a new instance of New.



8
9
10
11
12
13
# File 'lib/miso/commands.rb', line 8

def initialize(path, options = {})
  path.nil? && (raise UsageError.new('path not specified'))
  fail("#{path} already exists") if File.exist?(path)
  @path = path
  @options = options
end

Instance Method Details

#copy_template(src, dest) ⇒ Object



19
20
21
# File 'lib/miso/commands.rb', line 19

def copy_template(src, dest)
  FileUtils.cp(File.join(template_root, src), dest)
end

#copy_templates(templates) ⇒ Object



23
24
25
# File 'lib/miso/commands.rb', line 23

def copy_templates(templates)
  templates.each { |src, dest| copy_template(src, dest) }
end

#executeObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/miso/commands.rb', line 33

def execute
  make_directories
  templates = {
    'config.ru' => "#{@path}/config.ru",
    'Gemfile' => "#{@path}/Gemfile",
    '_app/miso/config.ru' => "#{@path}/_app/miso/config.ru",
    '_app/miso/miso.erb' => "#{@path}/_app/miso/miso.erb",
    '_site/index.html' => "#{@path}/_site/index.html"
  }
  copy_templates(templates)
end

#make_directoriesObject



27
28
29
30
31
# File 'lib/miso/commands.rb', line 27

def make_directories
  %w[_app/miso _site].each do |dir|
    FileUtils.mkdir_p(File.join(@path, dir))
  end
end

#template_rootObject



15
16
17
# File 'lib/miso/commands.rb', line 15

def template_root
  File.expand_path('../../template', File.dirname(__FILE__))
end