class LokaliseRails::TaskDefinition::Base

Attributes

api_client[W]

Public Class Methods

api_client() click to toggle source

Creates a Lokalise API client

@return [Lokalise::Client]

# File lib/lokalise_rails/task_definition/base.rb, line 15
def api_client
  @api_client ||= ::Lokalise.client LokaliseRails.api_token, {enable_compression: true}.merge(LokaliseRails.timeouts)
end
check_options_errors!() click to toggle source

Checks task options

@return Array

# File lib/lokalise_rails/task_definition/base.rb, line 28
def check_options_errors!
  errors = []
  errors << 'Project ID is not set!' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
  errors << 'Lokalise API token is not set!' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?

  raise(LokaliseRails::Error, errors.join(' ')) if errors.any?
end
reset_api_client!() click to toggle source

Resets API client

# File lib/lokalise_rails/task_definition/base.rb, line 20
def reset_api_client!
  Lokalise.reset_client!
  @api_client = nil
end

Private Class Methods

project_id_with_branch() click to toggle source

Returns Lokalise project ID and branch, semicolumn separated

@return [String]

# File lib/lokalise_rails/task_definition/base.rb, line 58
def project_id_with_branch
  "#{LokaliseRails.project_id}:#{LokaliseRails.branch}"
end
proper_ext?(raw_path) click to toggle source

Checks whether the provided file has a proper extension as dictated by the `file_ext_regexp` option

@return Boolean @param raw_path [String, Pathname]

# File lib/lokalise_rails/task_definition/base.rb, line 42
def proper_ext?(raw_path)
  path = raw_path.is_a?(Pathname) ? raw_path : Pathname.new(raw_path)
  LokaliseRails.file_ext_regexp.match? path.extname
end
subdir_and_filename_for(entry) click to toggle source

Returns directory and filename for the given entry

@return Array @param entry [String]

# File lib/lokalise_rails/task_definition/base.rb, line 51
def subdir_and_filename_for(entry)
  Pathname.new(entry).split
end
with_exp_backoff(max_retries) { || ... } click to toggle source

Sends request with exponential backoff mechanism

# File lib/lokalise_rails/task_definition/base.rb, line 63
def with_exp_backoff(max_retries)
  return unless block_given?

  retries = 0
  begin
    yield
  rescue Lokalise::Error::TooManyRequests => e
    raise(e.class, "Gave up after #{retries} retries") if retries >= max_retries

    sleep 2**retries
    retries += 1
    retry
  end
end