Module: Alchemy::Shell
- Included in:
- Seeder
- 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
-
#add_todo(todo) ⇒ Object
Adds a sentence to the todos Array.
- #desc(message) ⇒ Object
-
#display_todos ⇒ Object
Prints out all the todos.
-
#log(message, type = nil) ⇒ Object
Prints out the given log message with the color due to its type.
- #todo(todo, title = '') ⇒ Object
-
#todos ⇒ Array
All todos.
Class Method Details
.silence! ⇒ Object
10 11 12 |
# File 'lib/alchemy/shell.rb', line 10 def self.silence! @silenced = true end |
.silenced? ⇒ Boolean
18 19 20 |
# File 'lib/alchemy/shell.rb', line 18 def self.silenced? @silenced ||= false end |
.verbose! ⇒ Object
14 15 16 |
# File 'lib/alchemy/shell.rb', line 14 def self.verbose! @silenced = false end |
Instance Method Details
#add_todo(todo) ⇒ Object
Adds a sentence to the todos Array
37 38 39 |
# File 'lib/alchemy/shell.rb', line 37 def add_todo(todo) todos << todo end |
#desc(message) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/alchemy/shell.rb', line 22 def desc() unless Alchemy::Shell.silenced? puts "\n#{}" puts "#{'-' * .length}\n" end end |
#display_todos ⇒ Object
Prints out all the todos
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/alchemy/shell.rb', line 51 def display_todos if todos.length > 0 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 end |
#log(message, type = nil) ⇒ Object
Prints out the given log message with the color due to its type
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/alchemy/shell.rb', line 69 def log(, type=nil) unless Alchemy::Shell.silenced? case type when :skip puts "#{color(:yellow)}== Skipping! #{}#{color(:clear)}" when :error puts "#{color(:red)}!! ERROR: #{}#{color(:clear)}" when :message puts "#{color(:clear)}#{}" else puts "#{color(:green)}== #{}#{color(:clear)}" end end end |
#todo(todo, title = '') ⇒ Object
29 30 31 |
# File 'lib/alchemy/shell.rb', line 29 def todo(todo, title='') add_todo [title, todo] end |
#todos ⇒ Array
All todos
45 46 47 |
# File 'lib/alchemy/shell.rb', line 45 def todos @@todos ||= [] end |