Class: Hocon::Impl::SimpleConfigObject
- Inherits:
-
AbstractConfigObject
- Object
- AbstractConfigValue
- AbstractConfigObject
- Hocon::Impl::SimpleConfigObject
- Defined in:
- lib/hocon/impl/simple_config_object.rb
Constant Summary
Constants inherited from AbstractConfigValue
AbstractConfigValue::ConfigImplUtil
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from AbstractConfigValue
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #ignores_fallbacks? ⇒ Boolean
-
#initialize(origin, value, status = Hocon::Impl::ResolveStatus.from_values(value.values), ignores_fallbacks = false) ⇒ SimpleConfigObject
constructor
A new instance of SimpleConfigObject.
- #key_set ⇒ Object
- #merged_with_object(abstract_fallback) ⇒ Object
- #new_copy_with_status(new_status, new_origin, new_ignores_fallbacks = nil) ⇒ Object
- #render_value_to_sb(sb, indent_size, at_root, options) ⇒ Object
- #unwrapped ⇒ Object
Methods inherited from AbstractConfigObject
#merge_origins, #new_copy, #to_config, #to_fallback_value, #value_type
Methods inherited from AbstractConfigValue
#indent, #render, #render_to_sb, #require_not_ignoring_fallbacks, #resolve_status, #to_s, #with_fallback, #with_origin
Constructor Details
#initialize(origin, value, status = Hocon::Impl::ResolveStatus.from_values(value.values), ignores_fallbacks = false) ⇒ SimpleConfigObject
Returns a new instance of SimpleConfigObject.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hocon/impl/simple_config_object.rb', line 14 def initialize(origin, value, status = Hocon::Impl::ResolveStatus.from_values(value.values), ignores_fallbacks = false) super(origin) if value.nil? raise ConfigBugError, "creating config object with null map" end @value = value @resolved = (status == Hocon::Impl::ResolveStatus::RESOLVED) @ignores_fallbacks = ignores_fallbacks # Kind of an expensive debug check. Comment out? if status != Hocon::Impl::ResolveStatus.from_values(value.values) raise ConfigBugError, "Wrong resolved status on #{self}" end end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
31 32 33 |
# File 'lib/hocon/impl/simple_config_object.rb', line 31 def value @value end |
Class Method Details
.empty_missing(base_origin) ⇒ Object
8 9 10 11 12 |
# File 'lib/hocon/impl/simple_config_object.rb', line 8 def self.empty_missing(base_origin) self.new( Hocon::Impl::SimpleConfigOrigin.new_simple("#{base_origin.description} (not found)"), {}) end |
Instance Method Details
#empty? ⇒ Boolean
174 175 176 |
# File 'lib/hocon/impl/simple_config_object.rb', line 174 def empty? @value.empty? end |
#ignores_fallbacks? ⇒ Boolean
38 39 40 |
# File 'lib/hocon/impl/simple_config_object.rb', line 38 def ignores_fallbacks? @ignores_fallbacks end |
#key_set ⇒ Object
170 171 172 |
# File 'lib/hocon/impl/simple_config_object.rb', line 170 def key_set Set.new(@value.keys) end |
#merged_with_object(abstract_fallback) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 |
# File 'lib/hocon/impl/simple_config_object.rb', line 46 def merged_with_object(abstract_fallback) require_not_ignoring_fallbacks unless abstract_fallback.is_a?(Hocon::Impl::SimpleConfigObject) raise ConfigBugError, "should not be reached (merging non-SimpleConfigObject)" end fallback = abstract_fallback changed = false all_resolved = true merged = {} all_keys = key_set.union(fallback.key_set) all_keys.each do |key| first = @value[key] second = fallback.value[key] kept = if first.nil? second elsif second.nil? first else first.with_fallback(second) end merged[key] = kept if first != kept changed = true end if kept.resolve_status == Hocon::Impl::ResolveStatus::UNRESOLVED all_resolved = false end end new_resolve_status = Hocon::Impl::ResolveStatus.from_boolean(all_resolved) new_ignores_fallbacks = fallback.ignores_fallbacks? if changed Hocon::Impl::SimpleConfigObject.new(merge_origins([self, fallback]), merged, new_resolve_status, new_ignores_fallbacks) elsif (new_resolve_status != resolve_status) || (new_ignores_fallbacks != ignores_fallbacks?) newCopy(new_resolve_status, origin, new_ignores_fallbacks) else self end end |
#new_copy_with_status(new_status, new_origin, new_ignores_fallbacks = nil) ⇒ Object
33 34 35 36 |
# File 'lib/hocon/impl/simple_config_object.rb', line 33 def new_copy_with_status(new_status, new_origin, new_ignores_fallbacks = nil) Hocon::Impl::SimpleConfigObject.new(new_origin, @value, new_status, new_ignores_fallbacks) end |
#render_value_to_sb(sb, indent_size, at_root, options) ⇒ Object
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/hocon/impl/simple_config_object.rb', line 94 def render_value_to_sb(sb, indent_size, at_root, ) if empty? sb << "{}" else outer_braces = .json? || !at_root inner_indent = if outer_braces sb << "{" if .formatted? sb << "\n" end indent_size + 1 else indent_size end separator_count = 0 key_set.each do |k| v = @value[k] if .origin_comments? indent(sb, inner_indent, ) sb << "# " sb << v.origin.description sb << "\n" end if .comments? v.origin.comments.each do |comment| indent(sb, inner_indent, ) sb << "#" if !comment.start_with?(" ") sb << " " end sb << comment sb << "\n" end end indent(sb, inner_indent, ) v.render_to_sb(sb, inner_indent, false, k.to_s, ) if .formatted? if .json? sb << "," separator_count = 2 else separator_count = 1 end sb << "\n" else sb << "," separator_count = 1 end end # chop last commas/newlines # couldn't figure out a better way to chop characters off of the end of # the StringIO. This relies on making sure that, prior to returning the # final string, we take a substring that ends at sb.pos. sb.pos = sb.pos - separator_count if outer_braces if .formatted? sb << "\n" # put a newline back if outer_braces indent(sb, indent_size, ) end end sb << "}" end end if at_root && .formatted? sb << "\n" end end |
#unwrapped ⇒ Object
42 43 44 |
# File 'lib/hocon/impl/simple_config_object.rb', line 42 def unwrapped @value.merge(@value) { |k,v| v.unwrapped } end |