Class: LokaliseManager::TaskDefinitions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lokalise_manager/task_definitions/base.rb

Overview

Base class for LokaliseManager task definitions.

Provides shared functionality for Importer and Exporter classes, including:

  • API client management.
  • Configuration merging.
  • File validation helpers.
  • Exponential backoff for retrying failed API requests.

Direct Known Subclasses

Exporter, Importer

Constant Summary collapse

EXCEPTIONS =

Defines exceptions that should trigger a retry with exponential backoff.

  • JSON::ParserError: Occurs when the API responds with non-JSON content (e.g., HTML due to rate limits).
  • RubyLokaliseApi::Error::TooManyRequests: Raised when too many requests are sent in a short period.
[JSON::ParserError, RubyLokaliseApi::Error::TooManyRequests].freeze
CONFIG_KEYS =

All configuration-related keys

%i[
  api_token project_id import_opts import_safe_mode export_opts locales_path file_ext_regexp
  skip_file_export branch additional_client_opts translations_loader translations_converter
  lang_iso_inferer max_retries_export max_retries_import use_oauth2_token silent_mode
  raise_on_export_fail import_async export_preprocessor export_filename_generator
].freeze
BACKOFF_BASE_SECONDS =

base multiplier (1,2,4,8...)

1
BACKOFF_CAP_SECONDS =

max exponential backoff before jitter

32
BACKOFF_JITTER_RANGE =

adds rand * range

1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig) ⇒ Base

Initializes a new task object with merged global and custom configurations.

Parameters:

  • custom_opts (Hash) (defaults to: {})

    Custom configuration options specific to the task.

  • global_config (Object) (defaults to: LokaliseManager::GlobalConfig)

    The global configuration object.



42
43
44
45
# File 'lib/lokalise_manager/task_definitions/base.rb', line 42

def initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig)
  merged_opts = merge_configs(global_config, custom_opts)
  @config = build_config_class(merged_opts)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/lokalise_manager/task_definitions/base.rb', line 18

def config
  @config
end

Instance Method Details

#api_clientRubyLokaliseApi::Client

Retrieves or initializes the Lokalise API client based on the current configuration.

Returns:

  • (RubyLokaliseApi::Client)

    An instance of the Lokalise API client.



50
51
52
# File 'lib/lokalise_manager/task_definitions/base.rb', line 50

def api_client
  @api_client ||= create_api_client
end

#reset_api_client!Object

Resets the API client, clearing cached instances.

Useful when switching authentication tokens or handling connection issues.



57
58
59
60
61
# File 'lib/lokalise_manager/task_definitions/base.rb', line 57

def reset_api_client!
  ::RubyLokaliseApi.reset_client!
  ::RubyLokaliseApi.reset_oauth2_client!
  @api_client = nil
end