Sha256: 105b3cd91e15b25d34eb6788d4444cb4a4c1fa37e49f7e8fc89d9a940f5205e0

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'ruby-lokalise-api'
require 'pathname'

module LokaliseRails
  module TaskDefinition
    class Base
      class << self
        attr_writer :api_client

        # Creates a Lokalise API client
        #
        # @return [Lokalise::Client]
        def api_client
          @api_client ||= ::Lokalise.client LokaliseRails.api_token
        end

        # Checks task options
        #
        # @return Array
        def opt_errors
          errors = []
          errors << 'Project ID is not set! Aborting...' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
          errors << 'Lokalise API token is not set! Aborting...' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
          errors
        end

        private

        # Checks whether the provided file has a proper extension as dictated by the `file_ext_regexp` option
        #
        # @return Boolean
        # @param raw_path [String, Pathname]
        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

        # Returns directory and filename for the given entry
        #
        # @return Array
        # @param entry [String]
        def subdir_and_filename_for(entry)
          Pathname.new(entry).split
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lokalise_rails-1.0.1 lib/lokalise_rails/task_definition/base.rb
lokalise_rails-1.0.0 lib/lokalise_rails/task_definition/base.rb