Class: Hocon::Impl::AbstractConfigValue
- Inherits:
-
Object
- Object
- Hocon::Impl::AbstractConfigValue
show all
- 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().
Constant Summary
collapse
- ConfigImplUtil =
Hocon::Impl::ConfigImplUtil
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#at_key(origin, key) ⇒ Object
-
#at_path(origin, path) ⇒ Object
-
#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
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
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
#at_key(origin, key) ⇒ Object
#at_path(origin, path) ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/hocon/impl/abstract_config_value.rb', line 135
def at_path(origin, path)
parent = path.parent
result = at_key(origin, path.last)
while not parent.nil? do
key = parent.last
result = result.at_key(origin, key)
parent = parent.parent
end
result
end
|
#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?
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, options)
if options.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(options = Hocon::ConfigRenderOptions.defaults)
sb = StringIO.new
render_to_sb(sb, 0, true, nil, options)
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, options)
if !at_key.nil?
rendered_key =
if options.json?
ConfigImplUtil.render_json_string(at_key)
else
ConfigImplUtil.render_string_unquoted_if_possible(at_key)
end
sb << rendered_key
if options.json?
if options.formatted?
sb << " : "
else
sb << ":"
end
else
if self.is_a?(Hocon::ConfigObject)
if options.formatted?
sb << ' '
end
else
sb << "="
end
end
end
render_value_to_sb(sb, indent, at_root, options)
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, options)
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
|
#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
|