Class: Datagun::Api::Base
- Inherits:
-
Object
- Object
- Datagun::Api::Base
- Defined in:
- lib/datagun/api/base.rb
Overview
Base class for Datagun
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
-
.set_logger ⇒ Logger
Log to datagun.log file if Rails defined.
Instance Method Summary collapse
-
#initialize(default_logger: nil, version:) ⇒ Base
constructor
Initialize Datagun::Base.
Constructor Details
#initialize(default_logger: nil, version:) ⇒ Base
Initialize Datagun::Base
i.e. nil || Logger.new
17 18 19 20 21 |
# File 'lib/datagun/api/base.rb', line 17 def initialize(default_logger: nil, version:) @logger = default_logger || self.class.set_logger @api_url = Datagun.config.api_url || 'https://api.datagun.ai' @version = version end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/datagun/api/base.rb', line 9 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/datagun/api/base.rb', line 9 def logger @logger end |
Class Method Details
.set_logger ⇒ Logger
Log to datagun.log file if Rails defined.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datagun/api/base.rb', line 28 def self.set_logger @log_to ||= if defined?(::Rails) shift_age = 2 shift_size = 50 * 1024 * 1024 ::Logger.new("#{::Rails.root}/log/datagun.log", shift_age, shift_size) else ::Logger.new(STDOUT) end # Debug level on IRB or if logger_level is present on Thread.current @log_to.level = defined?(IRB) ? Logger::DEBUG : Thread.current[:logger_level] || Logger::INFO end |