class SolrMakr::Commands::Buffer

Captures output for buffers

@api private

Attributes

context[R]
exit_status[R]
logger[R]
output[R]

Public Class Methods

new(context: nil, **options) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 7
def initialize(context: nil, **options)
  @context  = context

  @output   = StringIO.new

  @logger   = Logger.new @output

  @logger.formatter = default_formatter

  @exit_status = 0
end

Public Instance Methods

default_formatter() click to toggle source

@return [Proc]

# File lib/solr_makr/commands/buffer.rb, line 84
def default_formatter
  proc do |severity, time, progname, message|
    context_name = progname.presence || context.presence || SolrMakr::BIN_NAME

    [].tap do |parts|
      parts << severity
      parts << "[#{time.iso8601}]" unless STDOUT.tty?
      parts << "[#{context_name}]" if context_name.present?
      parts << message
    end.join(' ') + "\n"
  end
end
error!(status: 1, message: nil) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 37
def error!(status: 1, message: nil)
  if message.present?
    logger.error message
  end

  if exit_status != status
    self.exit_status = status
  end
end
exit_status=(new_retval) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 71
def exit_status=(new_retval)
  @exit_status = Integer(new_retval) rescue -1
end
failure(message) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 53
def failure(message)
  print "\u2717 #{message}"
end
import(buffer) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 27
def import(buffer)
  write buffer.to_s

  unless buffer.success?
    self.exit_status = buffer.exit_status
  end

  return self
end
issue(message) click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 57
def issue(message)
  print "\u2757 #{message}"
end
ok(message = 'OK') click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 47
def ok(message = 'OK')
  print "\u2713 #{message}"
end
Also aliased as: success
print(*lines) click to toggle source
separator!() click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 61
def separator!
  write "\n\n"
end
success(message = 'OK')
Alias for: ok
success?() click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 75
def success?
  @exit_status.zero?
end
to_s() click to toggle source
# File lib/solr_makr/commands/buffer.rb, line 79
def to_s
  output.string
end