Class: SolrMakr::Commands::Buffer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/solr_makr/commands/buffer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Captures output for buffers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context: nil, **options) ⇒ Buffer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Buffer.



7
8
9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/solr_makr/commands/buffer.rb', line 19

def context
  @context
end

#exit_statusObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/solr_makr/commands/buffer.rb', line 22

def exit_status
  @exit_status
end

#loggerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/solr_makr/commands/buffer.rb', line 21

def logger
  @logger
end

#outputObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/solr_makr/commands/buffer.rb', line 20

def output
  @output
end

Instance Method Details

#default_formatterProc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Proc)


84
85
86
87
88
89
90
91
92
93
94
95
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
45
# 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

#failure(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/solr_makr/commands/buffer.rb', line 53

def failure(message)
  print "\u2717 #{message}"
end

#import(buffer) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
# File 'lib/solr_makr/commands/buffer.rb', line 57

def issue(message)
  print "\u2757 #{message}"
end

#ok(message = 'OK') ⇒ Object Also known as: success

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/solr_makr/commands/buffer.rb', line 47

def ok(message = 'OK')
  print "\u2713 #{message}"
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
# File 'lib/solr_makr/commands/buffer.rb', line 65

def print(*lines)
  lines.each { |line| write line }

  write "\n"
end

#separator!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
# File 'lib/solr_makr/commands/buffer.rb', line 61

def separator!
  write "\n\n"
end

#success?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


75
76
77
# File 'lib/solr_makr/commands/buffer.rb', line 75

def success?
  @exit_status.zero?
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/solr_makr/commands/buffer.rb', line 79

def to_s
  output.string
end