class Hocon::Impl::SimpleConfig
Constants
- ConfigMissingError
- ConfigNotResolvedError
- ConfigNullError
- ConfigValueType
The type of a configuration value (following the <a href=“JSONjson.org”>JSON> type schema).
- ConfigWrongTypeError
- DefaultTransformer
- Path
Attributes
object[R]
Public Class Methods
find_key(me, key, expected, original_path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 50 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.name(expected) : nil)), nil) elsif (not expected.nil?) && v.value_type != expected raise ConfigWrongTypeError.new(v.origin, "#{original_path.render} has type #{ConfigValueType.name(v.value_type)} " + "rather than #{ConfigValueType.name(expected)}", nil) else return v end end
find_key_or_null(me, key, expected, original_path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 109 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 != Hocon::ConfigValueType::NULL) raise Hocon::ConfigError::ConfigWrongTypeError.with_expected_actual(v.origin, original_path.render, expected.name, Hocon::ConfigValueType.name(v.value_type)) else return v end end
find_or_null(me, path, expected, original_path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 130 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, Hocon::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
new(object)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 24 def initialize(object) @object = object end
Public Instance Methods
==(other)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 97 def ==(other) if other.is_a? Hocon::Impl::SimpleConfig @object == other.object else false end end
at_key(key)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 309 def at_key(key) root.at_key(key) end
at_key_with_origin(origin, key)
click to toggle source
In java this is an overloaded version of atKey
# File lib/hocon/impl/simple_config.rb, line 314 def at_key_with_origin(origin, key) root.at_key_with_origin(origin, key) end
empty?()
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 305 def empty? @object.empty? end
find(me, path, expected, original_path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 75 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
find2(path_expression, expected)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 92 def find2(path_expression, expected) path = Path.new_path(path_expression) find3(path, expected, path) end
find3(path_expression, expected, original_path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 88 def find3(path_expression, expected, original_path) find(@object, path_expression, expected, original_path) end
get_any_ref(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 197 def get_any_ref(path) v = find2(path, nil) v.unwrapped end
get_boolean(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 165 def get_boolean(path) v = find2(path, ConfigValueType::BOOLEAN) v.unwrapped end
get_boolean_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 230 def get_boolean_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::BOOLEAN) end
get_bytes(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 202 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
get_config(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 193 def get_config(path) get_object(path).to_config end
get_config_number(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 170 def get_config_number(path_expression) path = Path.new_path(path_expression) v = find(@object, path, ConfigValueType::NUMBER, path) v.unwrapped end
get_double_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 247 def get_double_list(path) l = [] numbers = get_number_list(path) numbers.each do |n| l << n.double_value end l end
get_homogeneous_unwrapped_list(path, expected)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 213 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 #{expected.name}", "list of #{v.value_type.name}") end l << v.unwrapped end l end
get_homogeneous_wrapped_list(path, expected)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 264 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 #{expected.name}", "list of #{v.value_type.name}") end l << v end l end
get_int(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 176 def get_int(path) get_config_number(path) end
get_int_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 238 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
get_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 185 def get_list(path) find2(path, ConfigValueType::LIST) end
get_number_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 234 def get_number_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::NUMBER) end
get_object(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 189 def get_object(path) find2(path, ConfigValueType::OBJECT) end
get_object_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 260 def get_object_list(path) get_homogeneous_wrapped_list(path, ConfigValueType::OBJECT) end
get_string(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 180 def get_string(path) v = find2(path, ConfigValueType::STRING) v.unwrapped end
get_string_list(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 256 def get_string_list(path) get_homogeneous_unwrapped_list(path, ConfigValueType::STRING) end
get_value(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 160 def get_value(path) parsed_path = Path.new_path(path) find(@object, parsed_path, nil, parsed_path) end
has_path?(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 293 def has_path?(path_expression) peeked = has_path_peek(path_expression) (not peeked.nil?) && peeked.value_type != ConfigValueType::NULL end
has_path_or_null?(path)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 299 def has_path_or_null?(path) peeked = has_path_peek(path) not peeked.nil? end
has_path_peek(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 281 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
hash()
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 105 def hash 41 * @object.hash end
is_null?(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 154 def is_null?(path_expression) path = Path.new_path(path_expression) v = self.class.find_or_null(@object, path, nil, path) v.value_type == Hocon::ConfigValueType::NULL end
origin()
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 33 def origin @object.origin end
resolve(options = Hocon::ConfigResolveOptions.defaults)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 37 def resolve(options = Hocon::ConfigResolveOptions.defaults) resolve_with(self, options) end
resolve_with(source, options)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 41 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
root()
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 29 def root @object end
to_fallback_value()
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 333 def to_fallback_value @object end
with_fallback(other)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 337 def with_fallback(other) @object.with_fallback(other).to_config end
with_only_path(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 318 def with_only_path(path_expression) path = Path.new_path(path_expression) self.class.new(root.with_only_path(path)) end
with_value(path_expression, v)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 328 def with_value(path_expression, v) path = Path.new_path(path_expression) self.class.new(root.with_value(path, v)) end
without_path(path_expression)
click to toggle source
# File lib/hocon/impl/simple_config.rb, line 323 def without_path(path_expression) path = Path.new_path(path_expression) self.class.new(root.without_path(path)) end