Module: Cre

Defined in:
lib/cre.rb,
lib/cre/railtie.rb,
lib/cre/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'2.1.1'

Class Method Summary collapse

Class Method Details

.dig(*credentials) ⇒ Object

Fetching Rails encrypted credentials with:

`Rails.application.credentials.dig(:environment, :credential)`

Is too long for my taste. Using Cre.dig is a lot shorter:

`Cre.dig(:environment, :credential)`

By default Rails.env finds the default environment for us when none is specified and it is called with the credential only:

`Cre.dig(:password)`

The dig method here is just an aesthetic thing to keep us in context. TODO: Add support for deeply nested credentials.



16
17
18
19
20
21
22
23
# File 'lib/cre.rb', line 16

def self.dig(*credentials)
  env, credentials = if defined_environments.include? credentials[0].to_sym
    [credentials[0].to_sym, credentials[1..-1].flatten.map(&:to_sym)]
  else
    [Rails.env.to_sym, [credentials].flatten.map(&:to_sym)]
  end
  Rails.application.credentials.dig(env, *credentials)
end