Class: Conjur::Configuration
- Inherits:
-
Object
- Object
- Conjur::Configuration
- Defined in:
- lib/conjur/pubkeys-api.rb,
lib/conjur/configuration.rb
Instance Attribute Summary collapse
-
#explicit ⇒ Object
readonly
All explicit values.
-
#supplied ⇒ Object
readonly
All explicit and cached values.
Class Method Summary collapse
Instance Method Summary collapse
-
#clone(override_options) ⇒ Object
Copies the current configuration, except a set of overridden options.
-
#initialize(explicit = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(explicit = {}) ⇒ Configuration
Returns a new instance of Configuration.
51 52 53 54 |
# File 'lib/conjur/configuration.rb', line 51 def initialize explicit = {} @explicit = explicit.dup @supplied = explicit.dup end |
Instance Attribute Details
#explicit ⇒ Object (readonly)
All explicit values.
46 47 48 |
# File 'lib/conjur/configuration.rb', line 46 def explicit @explicit end |
#supplied ⇒ Object (readonly)
All explicit and cached values.
49 50 51 |
# File 'lib/conjur/configuration.rb', line 49 def supplied @supplied end |
Class Method Details
.accepted_options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 |
# File 'lib/conjur/configuration.rb', line 58 def require 'set' @options ||= Set.new end |
.add_option(name, options = {}, &def_proc) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 78 79 80 81 82 83 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 |
# File 'lib/conjur/configuration.rb', line 75 def add_option name, = {}, &def_proc << name allow_env = [:env].nil? || [:env] env_var = [:env] || "CONJUR_#{name.to_s.upcase}" def_val = [:default] opt_name = name def_proc ||= if def_val.respond_to?(:call) def_val elsif [:required] proc { raise "Missing required option #{opt_name}" } else proc { def_val } end convert = [:convert] || ->(x){ x } # Allow a Symbol, for example 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 instance_eval(&def_proc) end end alias_method("#{name}?", name) if [:boolean] end |
Instance Method Details
#clone(override_options) ⇒ Object
Copies the current configuration, except a set of overridden options.
116 117 118 |
# File 'lib/conjur/configuration.rb', line 116 def clone self.class.new self.explicit.dup.merge() end |
#set(key, value) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/conjur/configuration.rb', line 120 def set(key, value) if self.class..include?(key.to_sym) explicit[key.to_sym] = value supplied[key.to_sym] = value end end |