Class: Nero::EnvTag
Instance Attribute Summary
Attributes inherited from BaseTag
#coder, #ctx, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseTag
[], #args, #config, #init, #init_ctx, #init_with, #tag_name
Methods included from Resolvable
#deep_resolve, #gen_resolve_tryer, #resolve_nested!, #try_resolve
Class Method Details
permalink
.coerce_bool(v) ⇒ Object
[View source] [
View on GitHub]
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/nero.rb', line 198
def self.coerce_bool(v)
return false unless v
re_true = /y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON/
re_false = /n|N|no|No|NO|false|False|FALSE|off|Off|OFF/
case v
when TrueClass, FalseClass then v
when re_true then true
when re_false then false
else
raise "bool value should be one of y(es)/n(o), on/off, true/false (got #{v.inspect})"
end
end
|
permalink
.env_value(k, fallback = nil, optional: false) ⇒ Object
[View source] [
View on GitHub]
190
191
192
193
194
195
196
|
# File 'lib/nero.rb', line 190
def self.env_value(k, fallback = nil, optional: false)
if fallback.nil? && !optional
ENV.fetch(k)
else
ENV.fetch(k, fallback)
end
end
|
Instance Method Details
[View source] [
View on GitHub]
167
168
169
170
171
172
173
174
175
|
# File 'lib/nero.rb', line 167
def coercer
return unless @coerce
@coercer ||= case @coerce
when Symbol then @coerce.to_proc
else
@coerce
end
end
|
permalink
#init_options(coerce: nil) ⇒ Object
[View source] [
View on GitHub]
177
178
179
|
# File 'lib/nero.rb', line 177
def init_options(coerce: nil)
@coerce = coerce
end
|
permalink
#optional ⇒ Object
Also known as:
optional?
[View source] [
View on GitHub]
181
182
183
|
# File 'lib/nero.rb', line 181
def optional
tag_name.end_with?("?") || !!ENV["NERO_ENV_ALL_OPTIONAL"]
end
|
[View source] [
View on GitHub]
157
158
159
160
161
162
163
164
165
|
# File 'lib/nero.rb', line 157
def resolve(**)
if coercer
coercer.call(env_value) unless env_value.nil?
elsif ctx.dig(:tags, tag_name, :block)
super
else
env_value
end
end
|