Class: SelectRailsLog::Printer::BasePrinter

Inherits:
Extension
  • Object
show all
Includes:
Constants
Defined in:
lib/select_rails_log/printer/base_printer.rb

Constant Summary

Constants included from Constants

Constants::ACTION, Constants::CLIENT, Constants::COMPLETED, Constants::CONTROLLER, Constants::DEBUG, Constants::DEFAULT_OUTPUT, Constants::DURATION, Constants::HTTP_METHOD, Constants::HTTP_STATUS, Constants::ID, Constants::INTERVAL, Constants::LOGS, Constants::MESSAGE, Constants::PARAMETERS, Constants::PATH, Constants::PERFORMANCE, Constants::PERFORMANCE_ACTIVE_RECORD, Constants::PERFORMANCE_ALLOCATIONS, Constants::PERFORMANCE_VIEWS, Constants::PID, Constants::RAW_LOGS, Constants::REQUEST_ID, Constants::SEVERITY, Constants::STARTED, Constants::TIME

Instance Attribute Summary

Attributes inherited from Extension

#options

Instance Method Summary collapse

Methods inherited from Extension

option_initializers

Constructor Details

#initialize(options, standard_output) ⇒ BasePrinter

Returns a new instance of BasePrinter.



21
22
23
24
25
26
27
28
29
30
# File 'lib/select_rails_log/printer/base_printer.rb', line 21

def initialize(options, standard_output)
  super(options)

  @common_options = @whole_options[:base_printer]
  @output_file = @standard_output = standard_output
  @output_filename = @output_directory = nil
  init_output_destination

  @prepared = false
end

Instance Method Details

#closeObject



32
33
34
# File 'lib/select_rails_log/printer/base_printer.rb', line 32

def close
  @output_file&.close unless output_directory? || output_stdout?
end

#output_directory?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/select_rails_log/printer/base_printer.rb', line 55

def output_directory?
  !!@output_directory
end

#output_stdout?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/select_rails_log/printer/base_printer.rb', line 51

def output_stdout?
  !output_directory? && @output_file == @standard_output
end


36
37
38
39
40
41
42
43
44
45
# File 'lib/select_rails_log/printer/base_printer.rb', line 36

def print(data)
  unless @prepared
    prepare
    @prepared = true
  end

  with_output(data) do |io|
    print_data(io, data)
  end
end

#runnable?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/select_rails_log/printer/base_printer.rb', line 47

def runnable?
  !!output_option
end