Module: Ecertic::Utils

Defined in:
lib/ecertic/utils.rb

Class Method Summary collapse

Class Method Details

.encode_files(files) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/ecertic/utils.rb', line 11

def self.encode_files(files)
  files.map do |file|
    {
      pdf_filename: File.basename(file.path),
      pdf_content: Base64.strict_encode64(file.read),
    }
  end
end

.log_debug(message, data = {}) ⇒ Object



32
33
34
35
36
# File 'lib/ecertic/utils.rb', line 32

def self.log_debug(message, data = {})
  return unless should_log_for_level(Ecertic::LEVEL_DEBUG)

  log_internal(message, data, color: :orange, level: Ecertic::LEVEL_DEBUG, logger: Ecertic.logger, out: $stdout)
end

.log_error(message, data = {}) ⇒ Object



20
21
22
23
24
# File 'lib/ecertic/utils.rb', line 20

def self.log_error(message, data = {})
  return unless should_log_for_level(Ecertic::LEVEL_ERROR)

  log_internal(message, data, color: :red, level: Ecertic::LEVEL_ERROR, logger: Ecertic.logger, out: $stderr)
end

.log_info(message, data = {}) ⇒ Object



26
27
28
29
30
# File 'lib/ecertic/utils.rb', line 26

def self.log_info(message, data = {})
  return unless should_log_for_level(Ecertic::LEVEL_INFO)

  log_internal(message, data, color: :cyan, level: Ecertic::LEVEL_INFO, logger: Ecertic.logger, out: $stdout)
end

.should_log_for_level(level) ⇒ Object



38
39
40
# File 'lib/ecertic/utils.rb', line 38

def self.should_log_for_level(level)
  Ecertic.logger || Ecertic.log_level && Ecertic.log_level <= level
end

.validate_mandatory_attributes(attributes, required) ⇒ Object



5
6
7
8
9
# File 'lib/ecertic/utils.rb', line 5

def self.validate_mandatory_attributes(attributes, required)
  required.each do |name|
    attributes&.key?(name) || raise(ArgumentError, ":#{name} is required")
  end
end