Module: Docks::Messenger

Defined in:
lib/docks/messenger.rb

Constant Summary collapse

@@quiet =
false
@@header =
nil

Class Method Summary collapse

Class Method Details

.colorize(color, str) ⇒ Object



60
61
62
# File 'lib/docks/messenger.rb', line 60

def self.colorize(color, str)
  "\e[#{color}m#{str}\e[0m"
end

.created(*files) ⇒ Object



21
22
23
24
# File 'lib/docks/messenger.rb', line 21

def self.created(*files)
  puts 'Created the following files and directories:'
  created_files files
end

.created_files(*files) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/docks/messenger.rb', line 26

def self.created_files(*files)
  files.flatten.each do |file|
    puts "  #{file}"
    if File.directory? file
      created_files Dir["#{file}/*"]
    end
  end
end

.error(message) ⇒ Object



18
# File 'lib/docks/messenger.rb', line 18

def self.error(message); puts red("Error: #{message}") end

.file(file, action = :updated) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/docks/messenger.rb', line 35

def self.file(file, action = :updated)
  unless @@header.nil?
    puts "\n#{@@header}"
    puts "-" * @@header.length
    @@header = nil
  end

  file = file.to_s.sub((Docks.config.root || Pathname.pwd).to_s, "").sub(/^\//, "")

  case action
  when :updated then puts "Updated #{file}"
  when :created then puts green("Created #{file}")
  when :deleted then puts red("Deleted #{file}")
  end
end

.file_header(header) ⇒ Object



51
52
53
# File 'lib/docks/messenger.rb', line 51

def self.file_header(header)
  @@header = header
end

.green(str) ⇒ Object



66
# File 'lib/docks/messenger.rb', line 66

def self.green(str); colorize(32, str) end

.puts(str) ⇒ Object



16
# File 'lib/docks/messenger.rb', line 16

def self.puts(message); puts message end

.quietObject



6
7
8
9
# File 'lib/docks/messenger.rb', line 6

def self.quiet
  @@quiet = true
  self
end

.red(str) ⇒ Object



65
# File 'lib/docks/messenger.rb', line 65

def self.red(str); colorize(31, str) end

.showObject



11
12
13
14
# File 'lib/docks/messenger.rb', line 11

def self.show
  @@quiet = false
  self
end

.succeed(message) ⇒ Object



19
# File 'lib/docks/messenger.rb', line 19

def self.succeed(message); puts green(message) end

.warn(message) ⇒ Object



17
# File 'lib/docks/messenger.rb', line 17

def self.warn(message); puts yellow("Warning: #{message}") end

.yellow(str) ⇒ Object



64
# File 'lib/docks/messenger.rb', line 64

def self.yellow(str); colorize(33, str) end