Sha256: b7b40b7aad40d4c43041a6a1c6f812da50ebc2e7e19164a45600db1ce135b861

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require 'i18n/tasks/cli'
require 'i18n/tasks/reports/terminal'
require 'i18n/tasks/reports/spreadsheet'

module I18n::Tasks
  module Command
    class Commander
      include ::I18n::Tasks::Logging

      attr_reader :i18n


      # @param [I18n::Tasks::BaseTask] i18n
      def initialize(i18n)
        @i18n = i18n
      end

      def run(name, opts = {})
        name = name.to_sym
        public_name = name.to_s.tr '_'.freeze, '-'.freeze
        log_verbose "task: #{public_name}(#{opts.map { |k, v| "#{k}: #{v.inspect}" } * ', '.freeze})"
        if opts.empty? || method(name).arity.zero?
          send name
        else
          send name, opts
        end
      end

      def set_internal_locale!
        I18n.locale = i18n.internal_locale
      end

      protected

      def terminal_report
        @terminal_report ||= I18n::Tasks::Reports::Terminal.new(i18n)
      end

      def spreadsheet_report
        @spreadsheet_report ||= I18n::Tasks::Reports::Spreadsheet.new(i18n)
      end

      delegate :base_locale, :locales, :t, to: :i18n
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
i18n-tasks-0.9.2 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.9.1 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.9.0 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.9.0.rc2 lib/i18n/tasks/command/commander.rb