class Hocon::Impl::SimpleConfig
Constants
- ConfigMissingError
- ConfigNotResolvedError
- ConfigNullError
- ConfigValueType
-
The type of a configuration value (following the <a href=“json.org”>JSON</a> type schema).
- ConfigWrongTypeError
- DefaultTransformer
- Path
Attributes
Public Class Methods
Source
# File lib/hocon/impl/simple_config.rb, line 51 def self.find_key(me, key, expected, original_path) v = me.peek_assuming_resolved(key, original_path) if v.nil? raise ConfigMissingError.new(nil, "No configuration setting found for key '#{original_path.render}'", nil) end if not expected.nil? v = DefaultTransformer.transform(v, expected) end if v.value_type == ConfigValueType::NULL raise ConfigNullError.new(v.origin, (ConfigNullError.make_message(original_path.render, (not expected.nil?) ? ConfigValueType.value_type_name(expected) : nil)), nil) elsif (not expected.nil?) && v.value_type != expected raise ConfigWrongTypeError.new(v.origin, "#{original_path.render} has type #{ConfigValueType.value_type_name(v.value_type)} " + "rather than #{ConfigValueType.value_type_name(expected)}", nil) else return v end end
Source
# File lib/hocon/impl/simple_config.rb, line 110 def self.find_key_or_null(me, key, expected, original_path) v = me.peek_assuming_resolved(key, original_path) if v.nil? raise Hocon::ConfigError::ConfigMissingError.new(nil, original_path.render, nil) end if not expected.nil? v = Hocon::Impl::DefaultTransformer.transform(v, expected) end if (not expected.nil?) && (v.value_type != expected && v.value_type != ConfigValueType::NULL) raise Hocon::ConfigError::ConfigWrongTypeError.with_expected_actual(v.origin, original_path.render, ConfigValueType.value_type_name(expected), ConfigValueType.value_type_name(v.value_type)) else return v end end
Source
# File lib/hocon/impl/simple_config.rb, line 131 def self.find_or_null(me, path, expected, original_path) begin key = path.first remainder = path.remainder if remainder.nil? return self.find_key_or_null(me, key, expected, original_path) else o = find_key(me, key, ConfigValueType::OBJECT, original_path.sub_path(0, original_path.length - remainder.length)) if o.nil? raise "Missing key: #{key} on path: #{path}" end find_or_null(o, remainder, expected, original_path) end rescue Hocon::ConfigError::ConfigNotResolvedError raise Hocon::Impl::ConfigImpl::improved_not_resolved(path, e) end end
Source
# File lib/hocon/impl/simple_config.rb, line 25 def initialize(object) @object = object end
Public Instance Methods
Source
# File lib/hocon/impl/simple_config.rb, line 98 def ==(other) if other.is_a? Hocon::Impl::SimpleConfig @object == other.object else false end end
Source
# File lib/hocon/impl/simple_config.rb, line 310 def at_key(key) root.at_key(key) end
Source
# File lib/hocon/impl/simple_config.rb, line 315 def at_key_with_origin(origin, key) root.at_key_with_origin(origin, key) end
In java this is an overloaded version of atKey
Source
# File lib/hocon/impl/simple_config.rb, line 76 def find(me, path, expected, original_path) key = path.first rest = path.remainder if rest.nil? self.class.find_key(me, key, expected, original_path) else o = self.class.find_key(me, key, ConfigValueType::OBJECT, original_path.sub_path(0, original_path.length - rest.length)) raise "Error: object o is nil" unless not o.nil? find(o, rest, expected, original_path) end end
Source
# File lib/hocon/impl/simple_config.rb, line 93 def find2(path_expression, expected) path = Path.new_path(path_expression) find3(path, expected, path) end
Source
# File lib/hocon/impl/simple_config.rb, line 89 def find3(path_expression, expected, original_path) find(@object, path_expression, expected, original_path) end
Source
# File lib/hocon/impl/simple_config.rb, line 198 def get_any_ref(path) v = find2(path, nil) v.unwrapped end
Source
# File lib/hocon/impl/simple_config.rb, line 166 def get_boolean(path) v = find2(path, ConfigValueType::BOOLEAN) v.unwrapped end
Source
# File lib/hocon/impl/simple_config.rb, line 231 def get_boolean_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::BOOLEAN) end
Source
# File lib/hocon/impl/simple_config.rb, line 203 def get_bytes(path) size = null begin size = get_long(path) rescue ConfigWrongTypeError => e v = find2(path, ConfigValueType::STRING) size = self.class.parse_bytes(v.unwrapped, v.origin, path) end size end
Source
# File lib/hocon/impl/simple_config.rb, line 194 def get_config(path) get_object(path).to_config end
Source
# File lib/hocon/impl/simple_config.rb, line 171 def get_config_number(path_expression) path = Path.new_path(path_expression) v = find(@object, path, ConfigValueType::NUMBER, path) v.unwrapped end
Source
# File lib/hocon/impl/simple_config.rb, line 248 def get_double_list(path) l = [] numbers = get_number_list(path) numbers.each do |n| l << n.double_value end l end
Source
# File lib/hocon/impl/simple_config.rb, line 214 def get_homogeneous_unwrapped_list(path, expected) l = [] list = get_list(path) list.each do |cv| if !expected.nil? v = DefaultTransformer.transform(cv, expected) end if v.value_type != expected raise ConfigWrongTypeError.with_expected_actual(origin, path, "list of #{ConfigValueType.value_type_name(expected)}", "list of #{ConfigValueType.value_type_name(v.value_type)}") end l << v.unwrapped end l end
Source
# File lib/hocon/impl/simple_config.rb, line 265 def get_homogeneous_wrapped_list(path, expected) l = [] list = get_list(path) list.each do |cv| if !expected.nil? v = DefaultTransformer.transform(cv, expected) end if v.value_type != expected raise ConfigWrongTypeError.with_expected_actual(origin, path, "list of #{ConfigValueType.value_type_name(expected)}", "list of #{ConfigValueType.value_type_name(v.value_type)}") end l << v end l end
Source
# File lib/hocon/impl/simple_config.rb, line 177 def get_int(path) get_config_number(path) end
Source
# File lib/hocon/impl/simple_config.rb, line 239 def get_int_list(path) l = [] numbers = get_homogeneous_wrapped_list(path, ConfigValueType::NUMBER) numbers.each do |v| l << v.int_value_range_checked(path) end l end
Source
# File lib/hocon/impl/simple_config.rb, line 186 def get_list(path) find2(path, ConfigValueType::LIST) end
Source
# File lib/hocon/impl/simple_config.rb, line 235 def get_number_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::NUMBER) end
Source
# File lib/hocon/impl/simple_config.rb, line 190 def get_object(path) find2(path, ConfigValueType::OBJECT) end
Source
# File lib/hocon/impl/simple_config.rb, line 261 def get_object_list(path) get_homogeneous_wrapped_list(path, ConfigValueType::OBJECT) end
Source
# File lib/hocon/impl/simple_config.rb, line 181 def get_string(path) v = find2(path, ConfigValueType::STRING) v.unwrapped end
Source
# File lib/hocon/impl/simple_config.rb, line 257 def get_string_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::STRING) end
Source
# File lib/hocon/impl/simple_config.rb, line 161 def get_value(path) parsed_path = Path.new_path(path) find(@object, parsed_path, nil, parsed_path) end
Source
# File lib/hocon/impl/simple_config.rb, line 294 def has_path?(path_expression) peeked = has_path_peek(path_expression) (not peeked.nil?) && peeked.value_type != ConfigValueType::NULL end
Source
# File lib/hocon/impl/simple_config.rb, line 300 def has_path_or_null?(path) peeked = has_path_peek(path) not peeked.nil? end
Source
# File lib/hocon/impl/simple_config.rb, line 282 def has_path_peek(path_expression) path = Path.new_path(path_expression) begin peeked = @object.peek_path(path) rescue Hocon::ConfigError::ConfigNotResolvedError raise Hocon::Impl::ConfigImpl.improved_not_resolved(path, e) end peeked end
Source
# File lib/hocon/impl/simple_config.rb, line 155 def is_null?(path_expression) path = Path.new_path(path_expression) v = self.class.find_or_null(@object, path, nil, path) v.value_type == ConfigValueType::NULL end
Source
# File lib/hocon/impl/simple_config.rb, line 38 def resolve(options = Hocon::ConfigResolveOptions.defaults) resolve_with(self, options) end
Source
# File lib/hocon/impl/simple_config.rb, line 42 def resolve_with(source, options) resolved = Hocon::Impl::ResolveContext.resolve(@object, source.object, options) if resolved.eql?(@object) self else Hocon::Impl::SimpleConfig.new(resolved) end end
Source
# File lib/hocon/impl/simple_config.rb, line 334 def to_fallback_value @object end
Source
# File lib/hocon/impl/simple_config.rb, line 338 def with_fallback(other) @object.with_fallback(other).to_config end
Source
# File lib/hocon/impl/simple_config.rb, line 319 def with_only_path(path_expression) path = Path.new_path(path_expression) self.class.new(root.with_only_path(path)) end
Source
# File lib/hocon/impl/simple_config.rb, line 329 def with_value(path_expression, v) path = Path.new_path(path_expression) self.class.new(root.with_value(path, v)) end
Source
# File lib/hocon/impl/simple_config.rb, line 324 def without_path(path_expression) path = Path.new_path(path_expression) self.class.new(root.without_path(path)) end