Class: Dry::Credentials::Extension

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

Instance Method Summary collapse

Constructor Details

#initializeExtension

Returns a new instance of Extension.



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

Parameters:

  • setting (String)

    name of the setting

Returns:

  • (String)

    setting value



54
55
56
# File 'lib/dry/credentials/extension.rb', line 54

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

#[]=(setting, value) ⇒ Object

Change settings

Parameters:

  • setting (String)

    name of the setting

  • value (Object)

    new value of the setting



62
63
64
# File 'lib/dry/credentials/extension.rb', line 62

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

#edit!(env = nil) ⇒ self

Edit credentials file

Parameters:

  • env (String) (defaults to: nil)

    name of the env to edit the credentials for

Returns:

  • (self)


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

Returns:

  • (self)


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

Returns:

  • (self)


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