Class: Silicon::CLI
- Inherits:
-
Thor
- Object
- Thor
- Silicon::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/silicon/generators/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.source_root ⇒ Object
8 9 10 |
# File 'lib/silicon/generators/cli.rb', line 8 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#new(name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/silicon/generators/cli.rb', line 13 def new(name) copy_file 'templates/app/app.rb', "#{name}/app/app.rb" copy_file 'templates/app/app.routes', "#{name}/app/app.routes" copy_file 'templates/silicon.yml', "#{name}/silicon.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" copy_file 'templates/Gemfile', "#{name}/Gemfile" template 'templates/actions/welcome.tt', "#{name}/app/actions/welcome.rb", {app_name: name} inside name do run 'bundle' end end |
#routes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/silicon/generators/cli.rb', line 29 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 |