Class: Dry::Credentials::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/credentials/extension.rb

Instance Method Summary collapse

Constructor Details

#initializeExtension



7
8
9
10
# File 'lib/dry/credentials/extension.rb', line 7

def initialize
  @settings = Dry::Credentials::Settings.new
  @injected = []
end

Instance Method Details

#[](setting) ⇒ String

Query settings



68
69
70
# File 'lib/dry/credentials/extension.rb', line 68

def [](setting)
  @settings.send(setting)
end

#[]=(setting, value) ⇒ Object

Change settings



76
77
78
# File 'lib/dry/credentials/extension.rb', line 76

def []=(setting, value)
  @settings.send(setting, value)
end

#define!(key) {|Dry::Credentials::Extension| ... } ⇒ self

Define a dynamic secret

Yields:

Yield Returns:

  • (Object)

    dynamic secret

Raises:

  • (Types)

    description



58
59
60
61
62
# File 'lib/dry/credentials/extension.rb', line 58

def define!(key, &block)
  fail Dry::Credentials::DefineError if respond_to? key
  define_singleton_method(key) { block.call(self) }
  self
end

#edit!(env = nil) ⇒ self

Edit credentials file



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dry/credentials/extension.rb', line 36

def edit!(env=nil)
  helpers = Dry::Credentials::Helpers.new(self, env)
  create = helpers.create?
  yaml = read_yaml = helpers.read_yaml
  begin
    yaml = helpers.edit_yaml yaml
  end until helpers.yaml_valid? yaml
  unless yaml == read_yaml
    helpers.write_yaml yaml
    puts [helpers.key_ev, ENV[helpers.key_ev]].join('=') if create
    reload!
  end
end

#load!self

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.

Load the credentials once



16
17
18
19
20
21
22
# File 'lib/dry/credentials/extension.rb', line 16

def load!
  helpers = Dry::Credentials::Helpers.new(self)
  if  @injected.none? && !helpers.create?
    @injected = Dry::Credentials::YAML.new(helpers.read_yaml).inject_into(self)
  end
  self
end

#reload!self

Reload the credentials



27
28
29
30
# File 'lib/dry/credentials/extension.rb', line 27

def reload!
  singleton_class.undef_method(@injected.pop) until @injected.empty?
  self
end