Class: Loba::Internal::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/loba.rb

Overview

Internal class for managing logging across Rails and non-Rails applications

Class Method Summary collapse

Class Method Details

.loggerObject

Returns a logging mechanism appropriate for the application



268
269
270
271
272
273
274
# File 'lib/loba.rb', line 268

def logger
  if (rails? && Rails.logger.present?)
    ->(arg){Rails.logger.debug arg}
  else
    ->(arg){puts arg}
  end
end

.logging_ok?(force_true = false) ⇒ Boolean

Returns true if logging is to be allowed

Returns:

  • (Boolean)


257
258
259
260
261
262
263
264
265
# File 'lib/loba.rb', line 257

def logging_ok?(force_true = false)
  return true if force_true
  return true unless rails?
  begin
    !Rails.env.production?
  rescue
    true   # not Rails production if Rails isn't recognized
  end
end

.rails?Boolean

Returns true if Rails appears to be available

Returns:

  • (Boolean)


252
253
254
# File 'lib/loba.rb', line 252

def rails?
  defined?(Rails)
end