Sha256: a91e36f5e26b5ad03db0dbd1905f35cdc8829bc72b5d87d38b646c38d037c470

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# coding: utf-8
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

      def initialize(i18n = nil)
        @i18n = i18n
      end

      def run(name, opts = {})
        name = name.to_sym
        public_name = name.to_s.tr '_', '-'
        log_verbose "task: #{public_name}(#{opts.map { |k, v| "#{k}: #{v.inspect}" } * ', '})"
        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

      def i18n
        @i18n ||= I18n::Tasks::BaseTask.new
      end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
i18n-tasks-0.8.4 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.8.3 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.8.2 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.8.1 lib/i18n/tasks/command/commander.rb
i18n-tasks-0.8.0 lib/i18n/tasks/command/commander.rb