Class: Fastlane::Helper::Providers::BaseProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb

Overview

Abstract base class for all translation providers. Subclasses must implement all abstract methods to provide provider-specific translation functionality.

Constant Summary collapse

ANDROID_CHAR_LIMIT =

Maximum character length for Google Play release notes

500

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ BaseProvider

Initializes the provider with configuration parameters. Automatically validates the configuration.

Parameters:

  • params (Hash)

    Configuration parameters for the provider



17
18
19
20
21
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 17

def initialize(params)
  @params = params
  @config_errors = []
  validate_config!
end

Instance Attribute Details

#config_errorsObject (readonly)

Returns the value of attribute config_errors.



11
12
13
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 11

def config_errors
  @config_errors
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 11

def params
  @params
end

Class Method Details

.display_nameString

Returns the human-readable display name for the provider. Must be implemented by subclasses.

Returns:

  • (String)

    Human-readable name (e.g., ‘OpenAI GPT’, ‘Anthropic Claude’)

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 56

def self.display_name
  raise NotImplementedError, "#{name} must implement .display_name"
end

.optional_paramsHash

Returns a hash of optional parameter definitions for this provider. Keys are parameter names, values are hashes with :default and :description. Must be implemented by subclasses.

Returns:

  • (Hash)

    Optional parameter definitions

Raises:

  • (NotImplementedError)


73
74
75
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 73

def self.optional_params
  raise NotImplementedError, "#{name} must implement .optional_params"
end

.provider_nameString

Returns the provider identifier string. Must be implemented by subclasses.

Returns:

  • (String)

    Provider identifier (e.g., ‘openai’, ‘anthropic’)

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 48

def self.provider_name
  raise NotImplementedError, "#{name} must implement .provider_name"
end

.required_credentialsArray<Symbol>

Returns the list of required credential symbols for this provider. Must be implemented by subclasses.

Returns:

  • (Array<Symbol>)

    Array of required credential keys

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 64

def self.required_credentials
  raise NotImplementedError, "#{name} must implement .required_credentials"
end

Instance Method Details

#translate(text, source_locale, target_locale, glossary_terms: {}) ⇒ String?

Translates text from source locale to target locale. Must be implemented by subclasses.

Parameters:

  • text (String)

    The text to translate

  • source_locale (String)

    Source language code (e.g., ‘en’, ‘de’)

  • target_locale (String)

    Target language code (e.g., ‘es’, ‘fr’)

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

    Optional glossary { source_term => target_translation }

Returns:

  • (String, nil)

    Translated text or nil on error

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 31

def translate(text, source_locale, target_locale, glossary_terms: {})
  raise NotImplementedError, "#{self.class.name} must implement #translate"
end

#valid?Boolean

Checks if the provider configuration is valid.

Returns:

  • (Boolean)

    true if no configuration errors exist



80
81
82
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 80

def valid?
  @config_errors.empty?
end

#validate_config!void

This method returns an undefined value.

Validates provider-specific configuration. Should populate @config_errors with any validation failures. Must be implemented by subclasses.

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/base_provider.rb', line 40

def validate_config!
  raise NotImplementedError, "#{self.class.name} must implement #validate_config!"
end