module Alchemy::Shell

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

Constants

COLORS

Public Class Methods

silence!() click to toggle source
# File lib/alchemy/shell.rb, line 17
def self.silence!
  @silenced = true
end
silenced?() click to toggle source
# File lib/alchemy/shell.rb, line 25
def self.silenced?
  @silenced ||= false
end
verbose!() click to toggle source
# File lib/alchemy/shell.rb, line 21
def self.verbose!
  @silenced = false
end

Public Instance Methods

add_todo(todo) click to toggle source

Adds a sentence to the todos Array

@param [String] todo

# File lib/alchemy/shell.rb, line 44
def add_todo(todo)
  todos << todo
end
desc(message) click to toggle source
# File lib/alchemy/shell.rb, line 29
def desc(message)
  unless Alchemy::Shell.silenced?
    puts "\n#{message}"
    puts "#{"-" * message.length}\n"
  end
end
display_todos() click to toggle source

Prints out all the todos

# File lib/alchemy/shell.rb, line 58
def display_todos
  return if todos.empty?

  log "\n+---------+", :message
  log "| 📝 TODO |", :message
  log "+---------+\n", :message
  puts "\nWe did most of the work for you, but there are still some things left for you to do."
  todos.each_with_index do |todo, i|
    title = "\n#{i + 1}. #{todo[0]}"
    log title, :message
    puts "=" * title.length
    puts ""
    log todo[1], :message
  end
  puts ""
  puts "============================================================"
  puts "= ✨ Please take a minute and read the notes from above ✨ ="
  puts "============================================================"
  puts ""
end
log(message, type = nil) click to toggle source

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

@param [String] message @param [Symbol] type

# File lib/alchemy/shell.rb, line 84
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 = "") click to toggle source
# File lib/alchemy/shell.rb, line 36
def todo(todo, title = "")
  add_todo [title, todo]
end
todos() click to toggle source

All todos

@return [Array]

# File lib/alchemy/shell.rb, line 52
def todos
  @@todos ||= []
end

Private Instance Methods

color(name) click to toggle source

Gives the color string using Thor Used for colorizing the message on the shell

@param [String] name @return [String]

# File lib/alchemy/shell.rb, line 107
def color(name)
  COLORS[name]
end