Class: RailsWizard::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/rails_wizard/command.rb

Instance Method Summary collapse

Instance Method Details

#list(category = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rails_wizard/command.rb', line 33

def list(category = nil)
  if category
    scrolls = RailsWizard::Scrolls.for(category).map{|r| RailsWizard::Scroll.from_mongo(r) }
  else
    scrolls = RailsWizard::Scrolls.list_classes
  end

  scrolls.each do |scroll|
    puts scroll.key.ljust(15) + "# #{scroll.description}"
  end
end

#new(name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_wizard/command.rb', line 10

def new(name)
  if options[:scrolls]
    run_template(name, options[:scrolls], options[:template])
  else
    @scrolls = []

    while scroll = ask("#{print_scrolls}#{bold}Which scroll would you like to add? #{clear}#{yellow}(blank to finish)#{clear}")
      if scroll == ''
        run_template(name, @scrolls)
        break
      elsif RailsWizard::Scrolls.list.include?(scroll)
        @scrolls << scroll
        puts
        puts "> #{green}Added '#{scroll}' to template.#{clear}"
      else
        puts
        puts "> #{red}Invalid scroll, please try again.#{clear}"
      end
    end
  end
end