Class: ComplexConfig::KeySource
- Defined in:
- lib/complex_config/key_source.rb
Instance Method Summary collapse
-
#initialize(pathname: nil, env_var: nil, var: nil, master_key_pathname: nil) ⇒ KeySource
constructor
A new instance of KeySource.
- #key ⇒ Object
- #key_bytes ⇒ Object
- #master_key? ⇒ Boolean
Constructor Details
#initialize(pathname: nil, env_var: nil, var: nil, master_key_pathname: nil) ⇒ KeySource
Returns a new instance of KeySource.
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/complex_config/key_source.rb', line 2 def initialize(pathname: nil, env_var: nil, var: nil, master_key_pathname: nil) settings = [ pathname, env_var, var, master_key_pathname ].compact.size if settings > 1 raise ArgumentError, 'only one setting at most possible' end pathname and pathname = pathname.to_s master_key_pathname and master_key_pathname = master_key_pathname.to_s @pathname, @env_var, @var, @master_key_pathname = pathname, env_var, var, master_key_pathname end |
Instance Method Details
#key ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/complex_config/key_source.rb', line 17 def key if @var @var.ask_and_send(:chomp) elsif @env_var ENV[@env_var].ask_and_send(:chomp) elsif master_key? IO.binread(@master_key_pathname).chomp elsif @pathname IO.binread(@pathname + '.key').chomp end rescue Errno::ENOENT, Errno::ENOTDIR end |
#key_bytes ⇒ Object
30 31 32 |
# File 'lib/complex_config/key_source.rb', line 30 def key_bytes [ key ].pack('H*') end |
#master_key? ⇒ Boolean
13 14 15 |
# File 'lib/complex_config/key_source.rb', line 13 def master_key? !!@master_key_pathname end |