Class: Loba::Internal::Settings Private

Inherits:
Object
  • Object
show all
Defined in:
lib/loba/internal/settings.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.

Internal class for tracking output and logging settings based on supplied options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log: nil, logger: nil, logdev: nil, out: true, production: false) ⇒ Settings

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.

Note:

To avoid doubled output, if a non-Rails logger is to be logged to and logdev is set to $stdout, then output will be suppressed (i.e., settings.out is false). Doubled output can still occur; in that case, explicitly use out: false.

Returns a new instance of Settings.

Parameters:

  • log (boolean) (defaults to: nil)

    set to false if no logging is ever wanted (default when not in Rails and logger is nil); set to true if logging is always wanted (default when in Rails or when logger is set or out is false);

  • logger (Logger) (defaults to: nil)

    override logging with specified Ruby Logger

  • logdev (nil, String, IO, File::NULL) (defaults to: nil)

    custom log device to use (when not in Rails); ignored if logger is set; must be filename or IO object

  • out (boolean) (defaults to: true)

    set to false if console output is to be suppressed

  • production (boolean) (defaults to: false)

    set to true if Loba is to work even within a Rails production environment

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/loba/internal/settings.rb', line 43

def initialize(log: nil, logger: nil, logdev: nil, out: true, production: false)
  @raw_log_argument = log
  @log = validated_log(log)
  @out = false
  @production = validated_production(production)

  return unless enabled?

  @logger = validated_logger(logger)
  @logdev = validated_logdev(logdev)
  @out = validated_out(out)

  configure_logging
end

Instance Attribute Details

#logboolean (readonly) Also known as: log?

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 whether logging is performed.

Returns:

  • (boolean)

    whether logging is performed



6
7
8
# File 'lib/loba/internal/settings.rb', line 6

def log
  @log
end

#logdevnil, ... (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.

Returns any custom (overridden) logging device being written to; nil if none specified.

Returns:

  • (nil, String, IO, File::NULL)

    any custom (overridden) logging device being written to; nil if none specified



14
15
16
# File 'lib/loba/internal/settings.rb', line 14

def logdev
  @logdev
end

#loggerLogger (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.

Returns ::Logger used for logging; may be nil if not logging.

Returns:

  • (Logger)

    ::Logger used for logging; may be nil if not logging



10
11
12
# File 'lib/loba/internal/settings.rb', line 10

def logger
  @logger
end

#outboolean (readonly) Also known as: out?

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 false if console output is suppressed; otherwise, true.

Returns:

  • (boolean)

    false if console output is suppressed; otherwise, true



17
18
19
# File 'lib/loba/internal/settings.rb', line 17

def out
  @out
end

#productionboolean (readonly) Also known as: production?

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 true if Loba is enabled even within a Rails production environment; otherwise, false.

Returns:

  • (boolean)

    true if Loba is enabled even within a Rails production environment; otherwise, false



22
23
24
# File 'lib/loba/internal/settings.rb', line 22

def production
  @production
end

Instance Method Details

#disabled?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 true if Loba is skipped (because of a production environment); otherwise, false.

Returns:

  • (Boolean)

    true if Loba is skipped (because of a production environment); otherwise, false



65
66
67
# File 'lib/loba/internal/settings.rb', line 65

def disabled?
  !enabled?
end

#enabled?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 true if Loba is used; otherwise, false.

Returns:

  • (Boolean)

    true if Loba is used; otherwise, false



59
60
61
# File 'lib/loba/internal/settings.rb', line 59

def enabled?
  production? || !Internal::Platform::WithinRails.production?
end