Class: JennCad::Commands::NewProject

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
ActiveSupport::Inflector
Defined in:
lib/jenncad/commands.rb

Instance Method Summary collapse

Instance Method Details

#call(name:) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/jenncad/commands.rb', line 178

def call(name:, **)
  name = underscore(name)
  filename = name+".rb"
  Dir.mkdir(name)
  Dir.chdir(name)
  classname = camelize(name)
  File.open(filename, "w") do |f|
    f.puts "#!/usr/bin/env ruby"
    f.puts "require \"jenncad\""
    f.puts "include JennCad"
    f.puts ""
    f.puts "class #{classname} < Project"
    f.puts "  def config"
    f.puts "    {}"
    f.puts "  end"
    f.puts ""
    f.puts "  # #{MAGIC}"
    f.puts "end"
    f.puts ""
    f.puts "#{classname}.new.run"
  end
  File.chmod(0755, filename)

  puts "created new project #{name}"
end