Class: Datagun::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/datagun/api/base.rb

Overview

Base class for Datagun

Direct Known Subclasses

KeywordsExtractor::Client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_logger: nil, version:) ⇒ Base

Initialize Datagun::Base

i.e. nil || Logger.new

Parameters:

  • default_logger (Logger) (defaults to: nil)


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

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/datagun/api/base.rb', line 9

def client
  @client
end

#loggerObject (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_loggerLogger

Log to datagun.log file if Rails defined.

Returns:

  • (Logger)


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