Class: Hocon::Impl::ConfigImpl
- Inherits:
-
Object
- Object
- Hocon::Impl::ConfigImpl
- Defined in:
- lib/hocon/impl/config_impl.rb
Constant Summary collapse
- ConfigBugOrBrokenError =
Hocon::ConfigError::ConfigBugOrBrokenError
- ConfigNotResolvedError =
Hocon::ConfigError::ConfigNotResolvedError
- FromMapMode =
Hocon::Impl::FromMapMode
Class Method Summary collapse
- .default_includer ⇒ Object
- .empty_list(origin) ⇒ Object
- .empty_object(origin) ⇒ Object
- .from_any_ref(object, origin_description) ⇒ Object
- .from_any_ref_mode(object, origin, map_mode) ⇒ Object
- .improve_not_resolved(what, original) ⇒ Object
- .value_origin(origin_description) ⇒ Object
Class Method Details
.default_includer ⇒ Object
22 23 24 |
# File 'lib/hocon/impl/config_impl.rb', line 22 def self.default_includer @default_includer end |
.empty_list(origin) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/hocon/impl/config_impl.rb', line 53 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) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/hocon/impl/config_impl.rb', line 43 def self.empty_object(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 return default_empty_object else return Hocon::Impl::SimpleConfigObject.empty(origin) end end |
.from_any_ref(object, origin_description) ⇒ Object
61 62 63 64 |
# File 'lib/hocon/impl/config_impl.rb', line 61 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
66 67 68 69 70 71 72 73 74 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 |
# File 'lib/hocon/impl/config_impl.rb', line 66 def self.from_any_ref_mode(object, origin, map_mode) if origin.nil? raise ConfigBugOrBrokenError.new("origin not supposed to be nil", 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?(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.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::ConfigFloat.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(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}", nil) end value = self.from_any_ref_mode(entry, origin, map_mode) values[key] = value end return Hocon::Impl::SimpleConfigObject.new(origin, values) else return Hocon::Impl::PropertiesParser.from_path_map(origin, object) 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}", nil) end end |
.improve_not_resolved(what, original) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/hocon/impl/config_impl.rb', line 26 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 |
.value_origin(origin_description) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/hocon/impl/config_impl.rb', line 35 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 |