Class: Hocon::Impl::AbstractConfigValue
- Inherits:
-
Object
- Object
- Hocon::Impl::AbstractConfigValue
- Defined in:
- lib/hocon/impl/abstract_config_value.rb
Overview
Trying very hard to avoid a parent reference in config values; when you have a tree like this, the availability of parent() tends to result in a lot of improperly-factored and non-modular code. Please don’t add parent().
Direct Known Subclasses
AbstractConfigObject, ConfigConcatenation, ConfigNumber, ConfigString, SimpleConfigList
Constant Summary collapse
- ConfigImplUtil =
Hocon::Impl::ConfigImplUtil
Instance Attribute Summary collapse
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Instance Method Summary collapse
-
#ignores_fallbacks? ⇒ Boolean
this is virtualized rather than a field because only some subclasses really need to store the boolean, and they may be able to pack it with another boolean to save space.
- #indent(sb, indent_size, options) ⇒ Object
-
#initialize(origin) ⇒ AbstractConfigValue
constructor
A new instance of AbstractConfigValue.
- #render(options = Hocon::ConfigRenderOptions.defaults) ⇒ Object
- #render_to_sb(sb, indent, at_root, at_key, options) ⇒ Object
-
#render_value_to_sb(sb, indent, at_root, options) ⇒ Object
to be overridden by subclasses.
-
#require_not_ignoring_fallbacks ⇒ Object
the withFallback() implementation is supposed to avoid calling mergedWith* if we’re ignoring fallbacks.
- #resolve_status ⇒ Object
- #to_s ⇒ Object
- #with_fallback(mergeable) ⇒ Object
- #with_origin(origin) ⇒ Object
Constructor Details
#initialize(origin) ⇒ AbstractConfigValue
Returns a new instance of AbstractConfigValue.
18 19 20 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 18 def initialize(origin) @origin = origin end |
Instance Attribute Details
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
22 23 24 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 22 def origin @origin end |
Instance Method Details
#ignores_fallbacks? ⇒ Boolean
this is virtualized rather than a field because only some subclasses really need to store the boolean, and they may be able to pack it with another boolean to save space.
31 32 33 34 35 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 31 def ignores_fallbacks? # if we are not resolved, then somewhere in this value there's # a substitution that may need to look at the fallbacks. resolve_status == Hocon::Impl::ResolveStatus::RESOLVED end |
#indent(sb, indent_size, options) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 74 def indent(sb, indent_size, ) if .formatted? remaining = indent_size while remaining > 0 sb << " " remaining -= 1 end end end |
#render(options = Hocon::ConfigRenderOptions.defaults) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 121 def render( = Hocon::ConfigRenderOptions.defaults) sb = StringIO.new render_to_sb(sb, 0, true, nil, ) # We take a substring that ends at sb.pos, because we've been decrementing # sb.pos at various points in the code as a means to remove characters from # the end of the StringIO sb.string[0, sb.pos] end |
#render_to_sb(sb, indent, at_root, at_key, options) ⇒ Object
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 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 84 def render_to_sb(sb, indent, at_root, at_key, ) if !at_key.nil? rendered_key = if .json? ConfigImplUtil.render_json_string(at_key) else ConfigImplUtil.render_string_unquoted_if_possible(at_key) end sb << rendered_key if .json? if .formatted? sb << " : " else sb << ":" end else # in non-JSON we can omit the colon or equals before an object if self.is_a?(Hocon::ConfigObject) if .formatted? sb << ' ' end else sb << "=" end end end render_value_to_sb(sb, indent, at_root, ) end |
#render_value_to_sb(sb, indent, at_root, options) ⇒ Object
to be overridden by subclasses
116 117 118 119 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 116 def render_value_to_sb(sb, indent, at_root, ) u = unwrapped sb << u.to_s end |
#require_not_ignoring_fallbacks ⇒ Object
the withFallback() implementation is supposed to avoid calling mergedWith* if we’re ignoring fallbacks.
39 40 41 42 43 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 39 def require_not_ignoring_fallbacks if ignores_fallbacks? raise ConfigBugError, "method should not have been called with ignoresFallbacks=true #{self.class.name}" end end |
#resolve_status ⇒ Object
24 25 26 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 24 def resolve_status Hocon::Impl::ResolveStatus::RESOLVED end |
#to_s ⇒ Object
68 69 70 71 72 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 68 def to_s sb = StringIO.new render_to_sb(sb, 0, true, nil, Hocon::ConfigRenderOptions.concise) "#{self.class.name}(#{sb.string})" end |
#with_fallback(mergeable) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 53 def with_fallback(mergeable) if ignores_fallbacks? self else other = mergeable.to_fallback_value if other.is_a?(Hocon::Impl::Unmergeable) merged_with_the_unmergeable(other) elsif other.is_a?(Hocon::Impl::AbstractConfigObject) merged_with_object(other) else merged_with_non_object(other) end end end |
#with_origin(origin) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/hocon/impl/abstract_config_value.rb', line 45 def with_origin(origin) if @origin == origin self else new_copy(origin) end end |