Method: Translatomatic::Config#get

Defined in:
lib/translatomatic/config.rb

#get(key, context = nil) ⇒ String

Get a configuration setting

Parameters:

  • key (String)

    configuration key

  • context (Symbol) (defaults to: nil)

    configuration context. May be nil.

Returns:

  • (String)

    The configuration value. If context is nil, returns the effective value by precedence, otherwise it returns the setting for the given context.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/translatomatic/config.rb', line 52

def get(key, context = nil)
  key = check_valid_key(key)
  option = option(key)
  value = option.default  # set to default value

  if context.nil?
    # find the first setting in the following order
    CONTEXTS.each do |ctx|
      if @settings[ctx].include?(key)
        value = @settings[ctx][key]
        break
      end
    end
  else
    # context is set
    context = check_valid_context(context)
    if @settings[context].include?(key)
      value = @settings[context][key]
    end
  end

  # cast value to expected type
  cast(value, option.type)
end