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
93
94
95
|
# File 'lib/conjur/configuration.rb', line 55
def add_option name, options = {}, &def_proc
accepted_options << name
allow_env = options[:env].nil? || options[:env]
sticky = options.member?(:sticky) ? options[:sticky] : true
env_var = options[:env] || "CONJUR_#{name.to_s.upcase}"
def_val = options[:default]
opt_name = name
def_proc ||= if def_val.respond_to?(:call)
def_val
elsif options[:required]
proc { raise "Missing required option #{opt_name}" }
else
proc { def_val }
end
convert = options[:convert] || ->(x){ x }
convert = convert.to_proc if convert.respond_to?(:to_proc)
define_method("#{name}=") do |value|
set name, value
end
define_method("#{name}_env_var") do
allow_env ? env_var : nil
end
define_method(name) do
if supplied.member?(name)
supplied[name]
elsif allow_env && ENV.member?(env_var)
instance_exec(ENV[env_var], &convert)
else
value = instance_eval(&def_proc)
supplied[name] = value if sticky
value
end
end
alias_method("#{name}?", name) if options[:boolean]
end
|