Module: Datacaster::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/datacaster/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#i18n_existsObject

Returns the value of attribute i18n_exists.



6
7
8
# File 'lib/datacaster/config.rb', line 6

def i18n_exists
  @i18n_exists
end

#i18n_moduleObject

Returns the value of attribute i18n_module.



7
8
9
# File 'lib/datacaster/config.rb', line 7

def i18n_module
  @i18n_module
end

#i18n_tObject

Returns the value of attribute i18n_t.



5
6
7
# File 'lib/datacaster/config.rb', line 5

def i18n_t
  @i18n_t
end

Instance Method Details

#add_predefined_caster(name, definition) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/datacaster/config.rb', line 9

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

#i18n_exists?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/datacaster/config.rb', line 27

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

#i18n_initialize!Object



34
35
36
37
38
39
40
41
42
# File 'lib/datacaster/config.rb', line 34

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