Class: Hocon::Impl::SimpleConfig
- Inherits:
-
Object
- Object
- Hocon::Impl::SimpleConfig
- Defined in:
- lib/hocon/impl/simple_config.rb
Constant Summary collapse
- ConfigMissingError =
Hocon::ConfigError::ConfigMissingError
- ConfigNotResolvedError =
Hocon::ConfigError::ConfigNotResolvedError
- ConfigNullError =
Hocon::ConfigError::ConfigNullError
- ConfigWrongTypeError =
Hocon::ConfigError::ConfigWrongTypeError
- ConfigValueType =
Hocon::ConfigValueType
- Path =
Hocon::Impl::Path
- DefaultTransformer =
Hocon::Impl::DefaultTransformer
Instance Method Summary collapse
- #find(me, path, expected, original_path) ⇒ Object
- #find_key(me, key, expected, original_path) ⇒ Object
- #get_value(path) ⇒ Object
- #has_path(path_expression) ⇒ Object
-
#initialize(object) ⇒ SimpleConfig
constructor
A new instance of SimpleConfig.
- #root ⇒ Object
- #with_value(path_expression, v) ⇒ Object
- #without_path(path_expression) ⇒ Object
Constructor Details
#initialize(object) ⇒ SimpleConfig
Returns a new instance of SimpleConfig.
17 18 19 |
# File 'lib/hocon/impl/simple_config.rb', line 17 def initialize(object) @object = object end |
Instance Method Details
#find(me, path, expected, original_path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hocon/impl/simple_config.rb', line 50 def find(me, path, expected, original_path) key = path.first rest = path.remainder if rest.nil? find_key(me, key, expected, original_path) else o = 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 |
#find_key(me, key, expected, original_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hocon/impl/simple_config.rb', line 25 def 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.(original_path.render, (not expected.nil?) ? expected.name : nil)), nil) elsif (not expected.nil?) && v.value_type != expected raise ConfigWrongTypeError.new(v.origin, "#{original_path.render} has type #{v.value_type.name} " + "rather than #{expected.name}", nil) else return v end end |
#get_value(path) ⇒ Object
63 64 65 66 |
# File 'lib/hocon/impl/simple_config.rb', line 63 def get_value(path) parsed_path = Path.new_path(path) find(@object, parsed_path, nil, parsed_path) end |
#has_path(path_expression) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/hocon/impl/simple_config.rb', line 68 def has_path(path_expression) path = Path.new_path(path_expression) begin peeked = @object.peek_path(path) rescue ConfigNotResolvedError => e raise Hocon::Impl::ConfigImpl.improve_not_resolved(path, e) end (not peeked.nil?) && peeked.value_type != ConfigValueType::NULL end |
#root ⇒ Object
21 22 23 |
# File 'lib/hocon/impl/simple_config.rb', line 21 def root @object end |