Class: Dandy::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dandy/generators/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/dandy/generators/cli.rb', line 8

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#new(name) ⇒ Object



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/dandy/generators/cli.rb', line 14

def new(name)
  copy_file 'templates/.gitignore', "#{name}/.gitignore"

  if options[:jet_set]
    copy_file 'templates/app/app_jet_set.rb', "#{name}/app/app.rb"
    copy_file 'templates/Gemfile_jet_set', "#{name}/Gemfile"
    copy_file 'templates/db/mapping.rb', "#{name}/db/mapping.rb"
    copy_file 'templates/actions/common/open_db_session.rb', "#{name}/app/actions/common/open_db_session.rb"
  else
    copy_file 'templates/app/app.rb', "#{name}/app/app.rb"
    copy_file 'templates/Gemfile', "#{name}/Gemfile"
  end

  copy_file 'templates/app/app.routes', "#{name}/app/app.routes"
  copy_file 'templates/dandy.yml', "#{name}/dandy.yml"
  copy_file 'templates/config.ru', "#{name}/config.ru"
  copy_file 'templates/views/show_welcome.json.jbuilder', "#{name}/app/views/show_welcome.json.jbuilder"
  copy_file 'templates/actions/common/handle_errors.rb', "#{name}/app/actions/common/handle_errors.rb"
  template 'templates/actions/welcome.tt', "#{name}/app/actions/welcome.rb", {app_name: name}

  if options[:jet_set]
    insert_into_file "#{name}/app/app.routes", "        :before -> common/open_db_session\n", :after => ".->\n"
  end

  inside name do
    run 'bundle'
  end
end

#routesObject



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
# File 'lib/dandy/generators/cli.rb', line 44

def routes
  require './app/app'
  app = App.new

  headings = ['HTTP Verb', 'Path', 'Action Chain']
  rows = app.routes.map do |route|
    indent = ''
    commands = []
    route.commands.each_with_index do |c, index|
      indent += '  ' if c.sequential? && index > 0

      prefix = '->' if c.sequential?
      prefix = '=>' if c.parallel?
      prefix = '=*' if c.async?

      commands << "#{indent} #{prefix} #{c.name}"
    end


    commands = commands.join("\n")
    [route.http_verb, route.path, commands]
  end

  table = Terminal::Table.new(headings: headings, rows: rows)
  table.style = {all_separators: true}
  puts table
end