Sha256: faab5b5f957b4ce97fe20593c1b3fcace03b3b8da5fd07740239663c8a173e24

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

module Loba
  module Internal
    # Internal class for managing logging across Rails and non-Rails applications
    class Platform
      class << self
        # Returns true if Rails appears to be available
        def rails?
          defined?(Rails) ? true : false
        end

        # Returns true if logging is to be allowed
        def logging_ok?(force_true = false)
          return true if force_true
          return true unless rails?

          begin
            !Rails.env.production?
          rescue StandardError
            true # let it attempt to log anyway
          end
        end

        # Returns a logging mechanism appropriate for the application
        def logger
          if rails? && Rails.logger.present?
            ->(arg) { Rails.logger.debug arg }
          else
            ->(arg) { puts arg }
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loba-1.2.1 lib/loba/internal/platform.rb
loba-1.1.0 lib/loba/internal/platform.rb
loba-1.0.0 lib/loba/internal/platform.rb