Class: LokaliseManager::TaskDefinitions::Base
- Inherits:
-
Object
- Object
- LokaliseManager::TaskDefinitions::Base
- 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.
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
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#api_client ⇒ RubyLokaliseApi::Client
Retrieves or initializes the Lokalise API client based on the current configuration.
-
#initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig) ⇒ Base
constructor
Initializes a new task object with merged global and custom configurations.
-
#reset_api_client! ⇒ Object
Resets the API client, clearing cached instances.
Constructor Details
#initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig) ⇒ Base
Initializes a new task object with merged global and custom configurations.
30 31 32 33 |
# File 'lib/lokalise_manager/task_definitions/base.rb', line 30 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
#config ⇒ Object
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_client ⇒ RubyLokaliseApi::Client
Retrieves or initializes the Lokalise API client based on the current configuration.
38 39 40 |
# File 'lib/lokalise_manager/task_definitions/base.rb', line 38 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.
45 46 47 48 49 |
# File 'lib/lokalise_manager/task_definitions/base.rb', line 45 def reset_api_client! ::RubyLokaliseApi.reset_client! ::RubyLokaliseApi.reset_oauth2_client! @api_client = nil end |