Module: SeedHelper::OutputFormatter

Included in:
SeedHelper
Defined in:
lib/seed_helper/output_formatter.rb

Instance Method Summary collapse

Instance Method Details

#error(message, options = {}) ⇒ Object



31
32
33
34
35
# File 'lib/seed_helper/output_formatter.rb', line 31

def error(message, options = {})
  options[:prefix] ||= "  - "
  options[:color] ||= :red
  output message, options
end

#message(message, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/seed_helper/output_formatter.rb', line 19

def message(message, options = {})
  options[:prefix] ||= "*** "
  options[:color] ||= :white
  output message, options
end

#output(message, options = {}) ⇒ Object

Outputs a message with a set of given options

Examples:

Print out an error message

SeedHelper.output "Some error", {:prefix => "!!! ", :color => :red}
# outputs "!!! Some error" in red text

Parameters:

  • message: (String)

    The message to format

  • options: (Hash)

    A hash of options to apply to the string

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • prefix: (String)

    A prefix for the message. EG: “–> message”

  • color: (String)

    A Symbol representing the color from the Colored gem. See: Colored.colors

  • suffix: (String)

    A String suffix for the message. EG: “message !!!”



14
15
16
17
# File 'lib/seed_helper/output_formatter.rb', line 14

def output(message, options = {})
  options[:color] ||= :white
  $stdout.puts "#{options[:prefix]}#{message}#{options[:suffix]}".send(options[:color])
end

#resource_already_exists(resource) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/seed_helper/output_formatter.rb', line 37

def resource_already_exists(resource)
  message = "#{resource} already exists"

  options = {}
  options[:prefix] ||= "  > "
  options[:color]  ||= :cyan
  output(message, options)
end

#special_message(*lines) ⇒ Object



46
47
48
49
# File 'lib/seed_helper/output_formatter.rb', line 46

def special_message(*lines)
  $stdout.puts ""
  $stdout.puts lines.join("\n  ").magenta
end

#success(message, options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/seed_helper/output_formatter.rb', line 25

def success(message, options = {})
  options[:prefix] ||= "  + "
  options[:color] ||= :green
  output message, options
end