Class: AppScrollsScrolls::Command

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

Instance Method Summary collapse

Instance Method Details

#list(category = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/appscrolls/command.rb', line 37

def list(category = nil)
  if category
    scrolls = AppScrollsScrolls::Scrolls.for(category).map{|r| AppScrollsScrolls::Scroll.from_mongo(r) }
  else
    scrolls = AppScrollsScrolls::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
31
32
33
34
# File 'lib/appscrolls/command.rb', line 10

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

    question = "#{bold}Which scroll would you like to add/remove? #{clear}#{yellow}(blank to finish)#{clear}"
    while (scroll = ask(scrolls_message + question)) != ''
      if @scrolls.include?(scroll)
        @scrolls.delete(scroll)
        puts
        puts "> #{yellow}Removed '#{scroll}' from template.#{clear}"
      elsif AppScrollsScrolls::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

    run_template(name, @scrolls)
  end
end