Class: Montage::Commands::Init

Inherits:
Object
  • Object
show all
Extended by:
Montage::Commands
Defined in:
lib/montage/commands/init.rb

Overview

Creates a new project.

Constant Summary collapse

TEMPLATES =

Path to lib/templates

Pathname.new(__FILE__).dirname.parent + 'templates'

Constants included from Montage::Commands

BLANK

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Montage::Commands

config, exit, parse_options!

Constructor Details

#initialize(dir) ⇒ Init

Creates a new Generate instance.

Parameters:

  • The (Pathname)

    directory in which a new project is to be created.



38
39
40
# File 'lib/montage/commands/init.rb', line 38

def initialize(dir)
  @dir = Pathname.new(dir)
end

Class Method Details

.runObject

Creates a new project in the current directory.

Parameters:

  • argv (Array)

    The arguments given on the command line.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/montage/commands/init.rb', line 17

def self.run(*)
  new(Dir.pwd).run!

rescue Montage::ProjectExists => e
  if e.message.match(/`(.*)'$/)[1] == Dir.pwd
    say color("A Montage project already exists in the " \
      "current directory", :red)
  else
    say color(e.message.compress_lines, :red)
  end

  exit(1)
end

Instance Method Details

#run!Object

Runs the command, creating the new project structure.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/montage/commands/init.rb', line 44

def run!
  begin
    found = Project.find(@dir)
  rescue MissingProject
    ask_questions!
    make_directories!
    create_config!
    copy_sources!
    say color("Your project was created", :green)
    say Montage::Commands::BLANK
  else
    raise Montage::ProjectExists, <<-ERROR.compress_lines
      A Montage project exists in a parent directory at
      `#{found.paths.root}'
    ERROR
  end
end