Sha256: fbc28ae74c98a2b808a76db8158cb3d3fa460e43b149964196ca85d4786df287

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

module Datacaster
  module Config
    extend self

    attr_accessor :i18n_t
    attr_accessor :i18n_exists
    attr_accessor :i18n_module

    def add_predefined_caster(name, definition)
      case definition
      when Proc
        Predefined.define_method(name.to_sym, &definition)
      when Base
        Predefined.define_method(name.to_sym) { definition }
      else
        raise ArgumentError.new("Expected Datacaster defintion lambda or Datacaster instance")
      end
    end

    def i18n_t
      if @i18n_t.nil? && @i18n_module.nil?
        i18n_initialize!
      end
      @i18n_t || ->(*args, **kwargs) { @i18n_module.t(*args, **kwargs) }
    end

    def i18n_exists?
      if @i18n_t.nil? && @i18n_module.nil?
        i18n_initialize!
      end
      @i18n_exists || ->(*args, **kwargs) { @i18n_module.exists?(*args, **kwargs) }
    end

    def i18n_initialize!
      @i18n_module ||=
        if defined?(::I18n)
          I18n
        else
          SubstituteI18n
        end
      @i18n_module.load_path += [__dir__ + '/../../config/locales/en.yml']
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/config.rb
datacaster-4.0.1 lib/datacaster/config.rb
datacaster-3.3.1 lib/datacaster/config.rb
datacaster-3.3.0 lib/datacaster/config.rb
datacaster-3.2.7 lib/datacaster/config.rb
datacaster-3.2.6 lib/datacaster/config.rb
datacaster-3.2.5 lib/datacaster/config.rb
datacaster-3.2.4 lib/datacaster/config.rb
datacaster-3.2.3 lib/datacaster/config.rb
datacaster-3.2.2 lib/datacaster/config.rb
datacaster-3.2.1 lib/datacaster/config.rb
datacaster-3.2.0 lib/datacaster/config.rb
datacaster-3.1.5 lib/datacaster/config.rb