Class: Hocon::Impl::ConfigImpl
- Inherits:
-
Object
- Object
- Hocon::Impl::ConfigImpl
- Defined in:
- lib/hocon/impl/config_impl.rb
Defined Under Namespace
Classes: DebugHolder, EnvVariablesHolder, FileNameSource
Constant Summary collapse
- ConfigBugOrBrokenError =
Hocon::ConfigError::ConfigBugOrBrokenError
- ConfigNotResolvedError =
Hocon::ConfigError::ConfigNotResolvedError
- FromMapMode =
Hocon::Impl::FromMapMode
Class Method Summary collapse
- .default_includer ⇒ Object
- .default_reference ⇒ Object
- .empty_config(origin_description) ⇒ Object
- .empty_list(origin) ⇒ Object
- .empty_object(origin_description) ⇒ Object
- .empty_object_from_origin(origin) ⇒ Object
- .env_variables_as_config_object ⇒ Object
- .from_any_ref(object, origin_description) ⇒ Object
- .from_any_ref_mode(object, origin, map_mode) ⇒ Object
- .improve_not_resolved(what, original) ⇒ Object
- .parse_file_any_syntax(basename, base_options) ⇒ Object
- .trace(message, indent_level = 0) ⇒ Object
- .trace_loads_enabled ⇒ Object
- .trace_substitution_enabled ⇒ Object
- .value_origin(origin_description) ⇒ Object
Instance Method Summary collapse
Class Method Details
.default_includer ⇒ Object
27 28 29 |
# File 'lib/hocon/impl/config_impl.rb', line 27 def self.default_includer @default_includer end |
.default_reference ⇒ Object
229 230 231 232 233 |
# 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) ⇒ Object
221 222 223 |
# 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) ⇒ Object
62 63 64 65 66 67 68 |
# 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) ⇒ Object
211 212 213 214 215 216 217 218 219 |
# 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) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# 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 ⇒ Object
148 149 150 |
# 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) ⇒ Object
70 71 72 73 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# 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) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/hocon/impl/config_impl.rb', line 38 def self.improve_not_resolved(what, original) = "#{what.render} has not been resolved, you need to call Config#resolve, see API docs for Config#resolve" if == original. return original else return ConfigNotResolvedError.new(, original) end end |
.parse_file_any_syntax(basename, base_options) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/hocon/impl/config_impl.rb', line 55 def self.parse_file_any_syntax(basename, ) source = FileNameSource.new() Hocon::Impl::SimpleIncluder.from_basename(source, File.(basename), ) end |
.trace(message, indent_level = 0) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/hocon/impl/config_impl.rb', line 193 def self.trace(, indent_level = 0) while indent_level > 0 $stderr.putc(" ") indent_level -= 1 end $stderr.puts() end |
.trace_loads_enabled ⇒ Object
181 182 183 184 185 |
# 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 ⇒ Object
187 188 189 190 191 |
# 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) ⇒ Object
47 48 49 50 51 52 53 |
# 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 |
Instance Method Details
#empty(origin) ⇒ Object
225 226 227 |
# File 'lib/hocon/impl/config_impl.rb', line 225 def empty(origin) self.class.empty_object_from_origin(origin) end |