Module: Grape::Cli::Mongodb
- Defined in:
- lib/grape/cli/mongodb.rb,
lib/grape/cli/mongodb/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
Class Method Details
.execute ⇒ Object
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 |
# File 'lib/grape/cli/mongodb.rb', line 9 def self.execute = {} optparse = OptionParser.new do |opts| opts. = "Usage: grape [command] \"PROJECT_NAME\" [options]" opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end [:project_name] = nil opts.on( '-n', '--new PROJECT_NAME', 'Generate New Project' ) do |project| [:project_name] = project.downcase end # Define the options, and what they do [:verbose] = false opts.on( '-v', '--verbose', 'Output more information' ) do [:verbose] = true end end # Parse the command-line. the 'parse!' method parses ARGV and removes # any options found there, as well as any parameters for # the options. optparse.parse! if [:project_name] puts "Generating new project #{options[:project_name]}" new_project( filepath: Dir.pwd, project: [:project_name], verbose: [:verbose] ) end end |
.new_project(filepath: nil, project: nil, verbose: false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/grape/cli/mongodb.rb', line 43 def self.new_project(filepath: nil, project: nil, verbose: false) boilerplate = File.join( File.dirname(__FILE__), '/boilerplate' ) ## Copy the boilerplate directory to the filepath FileUtils.cp_r(boilerplate, filepath) ## rename the boilerplate directory to the project name FileUtils.mv( "#{filepath}/boilerplate", "#{filepath}/#{project}" ) new_path = "#{filepath}/#{project}" until File.directory?(new_path) print '.' end file_names = ['/init.rb', '/config.ru', '/config/entities.rb'] file_names.each do |file_name| text = File.read( File.join(new_path, file_name) ) replace_module = text.gsub('BOILERPLATE', project.upcase.gsub('_', '')) File.open(File.join(new_path, file_name), 'w') { |file| file.puts replace_module } puts "created file ./#{file_name}" end config_files = ['/config/mongoid.yml'] config_files.each do |file_name| text = File.read( File.join(new_path, file_name) ) replace_db = text.gsub( 'boilerplate', project ) File.open( File.join(new_path, file_name), 'w' ) { |file| file.puts replace_db } puts "created file ./#{file_name}" end folders_to_make = ['entities', 'lib', 'log', 'bin', 'models', 'resources', 'tasks'] folders_to_make.each do |folder| Dir.mkdir( File.join(new_path, folder) ) puts "created directory ./#{folder}" end ## create emty folders ## entities ## lib ## log ## bin ## models ## resources ## tasks end |