class Hocon::Impl::ConfigImpl
Constants
- ConfigBugOrBrokenError
- ConfigNotResolvedError
- FromMapMode
Public Class Methods
default_includer()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 27 def self.default_includer @default_includer end
default_reference()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 229 def self.default_reference resource = Hocon::Impl::Parseable.new_resources("reference.conf", Hocon::ConfigParseOptions.defaults) resource.parse.to_config end
empty_config(origin_description)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 221 def self.empty_config(origin_description) empty_object(origin_description).to_config end
empty_list(origin)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 62 def self.empty_list(origin) if origin.nil? || origin == @default_value_origin return @default_empty_list else return Hocon::Impl::SimpleConfigList.new(origin, Array.new) end end
empty_object(origin_description)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 211 def self.empty_object(origin_description) if !origin_description.nil? origin = Hocon::Impl::SimpleConfigOrigin.new_simple(origin_description) else origin = nil end empty_object_from_origin(origin) end
empty_object_from_origin(origin)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 201 def self.empty_object_from_origin(origin) # we want null origin to go to SimpleConfigObject.empty() to get the # origin "empty config" rather than "hardcoded value" if origin == @default_value_origin @default_empty_object else Hocon::Impl::SimpleConfigObject.empty(origin) end end
env_variables_as_config_object()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 148 def self.env_variables_as_config_object EnvVariablesHolder.get_env_variables end
from_any_ref(object, origin_description)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 70 def self.from_any_ref(object, origin_description) origin = self.value_origin(origin_description) from_any_ref_mode(object, origin, FromMapMode::KEYS_ARE_KEYS) end
from_any_ref_mode(object, origin, map_mode)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 75 def self.from_any_ref_mode(object, origin, map_mode) if origin.nil? raise ConfigBugOrBrokenError.new("origin not supposed to be nil") end if object.nil? if origin != @default_value_origin return Hocon::Impl::ConfigNull.new(origin) else return @default_null_value end elsif object.is_a?(Hocon::Impl::AbstractConfigValue) return object elsif object.is_a?(TrueClass) || object.is_a?(FalseClass) if origin != @default_value_origin return Hocon::Impl::ConfigBoolean.new(origin, object) elsif object return @default_true_value else return @default_false_value end elsif object.is_a?(String) return Hocon::Impl::ConfigString::Quoted.new(origin, object) elsif object.is_a?(Numeric) # here we always keep the same type that was passed to us, # rather than figuring out if a Long would fit in an Int # or a Double has no fractional part. i.e. deliberately # not using ConfigNumber.newNumber() when we have a # Double, Integer, or Long. if object.is_a?(Float) return Hocon::Impl::ConfigDouble.new(origin, object, nil) elsif object.is_a?(Integer) return Hocon::Impl::ConfigInt.new(origin, object, nil) else return Hocon::Impl::ConfigNumber.new_number(origin, Float(object), nil) end elsif object.is_a?(Hash) if object.empty? return self.empty_object_from_origin(origin) end if map_mode == FromMapMode::KEYS_ARE_KEYS values = Hash.new object.each do |key, entry| if not key.is_a?(String) raise ConfigBugOrBrokenError.new( "bug in method caller: not valid to create ConfigObject from map with non-String key: #{key}") end value = self.from_any_ref_mode(entry, origin, map_mode) values[key] = value end return Hocon::Impl::SimpleConfigObject.new(origin, values) else raise ConfigBugOrBrokenError, "java properties format not supported" end elsif object.is_a?(Enumerable) if object.count == 0 return self.empty_list(origin) end values = Array.new object.each do |item| v = from_any_ref_mode(item, origin, map_mode) values.push(v) end return Hocon::Impl::SimpleConfigList.new(origin, values) else raise ConfigBugOrBrokenError.new("bug in method caller: not valid to create ConfigValue from: #{object}") end end
improve_not_resolved(what, original)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 38 def self.improve_not_resolved(what, original) new_message = "#{what.render} has not been resolved, you need to call Config#resolve, see API docs for Config#resolve" if new_message == original.message return original else return ConfigNotResolvedError.new(new_message, original) end end
parse_file_any_syntax(basename, base_options)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 55 def self.parse_file_any_syntax(basename, base_options) source = FileNameSource.new() Hocon::Impl::SimpleIncluder.from_basename(source, File.expand_path(basename), base_options) end
trace(message, indent_level = 0)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 193 def self.trace(message, indent_level = 0) while indent_level > 0 $stderr.putc(" ") indent_level -= 1 end $stderr.puts(message) end
trace_loads_enabled()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 181 def self.trace_loads_enabled # Ignoring 'catch ExceptionInInitializerError' from that java version, # that is just terrible java code anyway. DebugHolder.trace_loads_enabled end
trace_substitution_enabled()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 187 def self.trace_substitution_enabled # Ignoring 'catch ExceptionInInitializerError' from that java version, # that is just terrible java code anyway. DebugHolder.trace_substitutions_enabled end
value_origin(origin_description)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 47 def self.value_origin(origin_description) if origin_description.nil? return @default_value_origin else return Hocon::Impl::SimpleConfigOrigin.new_simple(origin_description) end end
Private Class Methods
load_env_variables()
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 237 def self.load_env_variables env = ENV m = {} env.each do |key, value| m[key] = Hocon::Impl::ConfigString::Quoted.new( Hocon::Impl::SimpleConfigOrigin.new_simple("env var #{key}"), value) end Hocon::Impl::SimpleConfigObject.new( Hocon::Impl::SimpleConfigOrigin.new_simple("env variables"), m, Hocon::Impl::ResolveStatus::RESOLVED, false) end
Public Instance Methods
empty(origin)
click to toggle source
# File lib/hocon/impl/config_impl.rb, line 225 def empty(origin) self.class.empty_object_from_origin(origin) end