Module: Alchemy::Shell

Included in:
Seeder, Tidy, Upgrader
Defined in:
lib/alchemy/shell.rb

Overview

Provides methods for collecting sentences and displaying them in a list on the shell / log

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.silence!Object



8
9
10
# File 'lib/alchemy/shell.rb', line 8

def self.silence!
  @silenced = true
end

.silenced?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/alchemy/shell.rb', line 16

def self.silenced?
  @silenced ||= false
end

.verbose!Object



12
13
14
# File 'lib/alchemy/shell.rb', line 12

def self.verbose!
  @silenced = false
end

Instance Method Details

#add_todo(todo) ⇒ Object

Adds a sentence to the todos Array

Parameters:

  • todo (String)


35
36
37
# File 'lib/alchemy/shell.rb', line 35

def add_todo(todo)
  todos << todo
end

#desc(message) ⇒ Object



20
21
22
23
24
25
# File 'lib/alchemy/shell.rb', line 20

def desc(message)
  unless Alchemy::Shell.silenced?
    puts "\n#{message}"
    puts "#{'-' * message.length}\n"
  end
end

#display_todosObject

Prints out all the todos



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/alchemy/shell.rb', line 49

def display_todos
  return if todos.empty?

  log "\nTODOs:", :message
  log "------\n", :message
  todos.each_with_index do |todo, i|
    title = "\n#{i + 1}. #{todo[0]}"
    log title, :message
    puts '-' * title.length
    log todo[1], :message
  end
end

#log(message, type = nil) ⇒ Object

Prints out the given log message with the color due to its type

Parameters:

  • message (String)
  • type (Symbol) (defaults to: nil)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/alchemy/shell.rb', line 67

def log(message, type = nil)
  unless Alchemy::Shell.silenced?
    case type
    when :skip
      puts "#{color(:yellow)}== Skipping! #{message}#{color(:clear)}"
    when :error
      puts "#{color(:red)}!! ERROR: #{message}#{color(:clear)}"
    when :message
      puts "#{color(:clear)}#{message}"
    else
      puts "#{color(:green)}== #{message}#{color(:clear)}"
    end
  end
end

#todo(todo, title = '') ⇒ Object



27
28
29
# File 'lib/alchemy/shell.rb', line 27

def todo(todo, title = '')
  add_todo [title, todo]
end

#todosArray

All todos

Returns:

  • (Array)


43
44
45
# File 'lib/alchemy/shell.rb', line 43

def todos
  @@todos ||= []
end