class Liberic::Config
Provides an interface to ERiC's configuration parameters and logging.
Scope¶ ↑
This class is not meant to be instantiated directly. An instance is created the first time it is accessed in the Liberic
namespace.
Liberic.config # will return an instance of Config
Configuration parameters¶ ↑
Configuration parameters can be accessed with the hash notation. Keys are passed to ERiC directly, so they must be in German (see ERiC documentation for this).
Example:
Liberic.config['validieren.fehler_max'] # 30
Config
provides an english abstraction to these parameters with attr_accessor
like getter/setter methods:
Liberic.config.validation_error_limit = 30
The most common settings are (german names in paranthesis)
-
data_path
(basis.data_dir) directory to store PDFs and certificates in -
allow_test_id
(basis.test_id_erlaubt) allow fake tax ids when processing tax filings -
detailed_logs
(log.detailed) set log level to debug. Also disables rolling logs (ifdetailed_logs
isfalse
, ERiC will create a maximum of ten log files on disk, each with 1 MB of size. The oldest file will be deleted when rolling over). WARNING: Logging to disk is disabled after instantiatingConfig
. See:logger:
for details. -
validation_error_limit
(validieren.fehler_max) limits the amount of errors that are returned when processing or checking tax filings. This means even though 50 fields inside the tax report are missing, only the first 30 are reported as part of the response. -
online
(transfer.netz.doi) allow connecting to the actual tax authority's production systems.
Attributes
Public Class Methods
# File lib/liberic/config.rb, line 38 def initialize install_logger end
Public Instance Methods
# File lib/liberic/config.rb, line 95 def [](key) convert_to_ruby( Helpers::Invocation.with_result_buffer do |handle| SDK::API.einstellung_lesen(key, handle) end ) end
# File lib/liberic/config.rb, line 103 def []=(key, value) Helpers::Invocation.raise_on_error( SDK::API.einstellung_setzen( key, convert_to_eric(value) ) ) end
Assign an instance of Logger that will be called whenever ERiC creates log output. Please note that ERiC's mechanism to write log files to disk is disabled as soon as a Config
class is instantiated!
Attributes¶ ↑
-
logger
- A Ruby Logger instance or nil
Examples¶ ↑
An instance of Config
is provided in the Liberic
namespace. A logger can be assigned like this:
Liberic.config.logger = Logger.new(STDOUT) Liberic.config.logger.level = Logger::WARN
ERiC does not send debug log messages by default. To do this, change ERiC's configuration:
Liberic.config.detailed_logs = true
and make sure :level:
of your Logger
is not filtering debug messages.
# File lib/liberic/config.rb, line 66 def logger=(logger) @logger = logger end
Private Instance Methods
# File lib/liberic/config.rb, line 138 def convert_to_eric(value) if [true, false].include?(value) value ? 'ja' : 'nein' else value end.to_s.encode(SDK::Configuration::ENCODING) end
# File lib/liberic/config.rb, line 126 def convert_to_ruby(value) if value.to_i.to_s == value value.to_i elsif ['ja', 'yes'].include?(value.downcase) true elsif ['nein', 'no'].include?(value.downcase) false else value.force_encoding(SDK::Configuration::ENCODING).encode(Encoding::default_external) end end
# File lib/liberic/config.rb, line 146 def get(key) Helpers::Invocation.with_result_buffer(true) do |handle| SDK::API.einstellung_lesen(key, handle) end end
# File lib/liberic/config.rb, line 114 def install_logger Helpers::Invocation.raise_on_error( SDK::API.registriere_log_callback( SDK::API.generate_log_callback do |category, level, message| if @logger.respond_to?(:add) @logger.add(SDK::Types::LOGGER_SEVERITY[level], message, category) end end, 0, nil) ) end
# File lib/liberic/config.rb, line 152 def set(key, value) Helpers::Invocation.raise_on_error(SDK::API.einstellung_setzen(key, value)) true end