cre 2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/lib/cre.rb +13 -5
  4. data/lib/cre/version.rb +1 -1
  5. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bef30156d8819248f6c3ac284dae7db22d7ab1959756424d165d776187d8695
4
- data.tar.gz: 0dc782a721b2b0d1c0f1e262edb4e82d13de5e72059a316d11e7a78f0996f7a3
3
+ metadata.gz: cf0ccab29a3078c0e4d71a116f3b3b62c462491979f04b4013383784dad9414e
4
+ data.tar.gz: f1b7b6f3ff7f326f9da48e011340ccbf45b8094b3388a8985aeb85c2f922b21f
5
5
  SHA512:
6
- metadata.gz: 171038f321ee1feaf53fcaddb85b6b8d76032489315279686046a0ab79df2c58e0352503e6c8cfd678e70244cf4a99e952ff0a6180f9ba0ae48404c04528f7da
7
- data.tar.gz: c3bd5f381e66d620e76a41b65481dcbd828f5babe95114c5369a60a71b558b0a3274deb0d094d6dda91eb86e61e30165564a0ee6b3b796be97f53f1f100d0547
6
+ metadata.gz: c12abb3409d58f4237cbf0893f07bdecfeeb61e7546dde866fde4c8bcd4d62da744601a040cfdeb4a3448d5094d07032455cd3df6aa3fb880b5e86472d25dbe2
7
+ data.tar.gz: e1791a9e14e1cc4abeff3f6598d36b2c212cfc5f185a0d7774b8759fbc843cd2087eb4a16c3e248a131eb51370291db1689b9c5b5ee82040bfd869325218b7f3
data/README.md CHANGED
@@ -11,6 +11,7 @@ Instead of going the long way:
11
11
  ## Usage
12
12
  By default it uses the currently active rails environment.
13
13
  Specify the environment specifically by adding it as the first argument.
14
+ But do remember that it only considers `defined environments` in `config/environments`
14
15
 
15
16
  `Cre.dig(:production, :password)`
16
17
 
@@ -25,6 +26,14 @@ development:
25
26
  test:
26
27
  aws_key: 'somekeytest'
27
28
  password: 'fakepass'
29
+ ```
30
+ It also supports deeper nested credentials for example:
31
+ ```
32
+ Cre.dig(:production, :aws, :client, secret, :key)
33
+ ```
34
+ Or:
35
+ ```
36
+ Cre.dig(:something, :nested, :multiple, :layers, :deep)
28
37
  ```
29
38
  ## Installation
30
39
  Add this line to your application's Gemfile:
@@ -44,7 +53,6 @@ $ gem install cre
44
53
  ```
45
54
 
46
55
  ##Todo:
47
- - Add support for more and less levels of nesting.
48
56
  - Exeption handeling
49
57
 
50
58
  ## Contributing
data/lib/cre.rb CHANGED
@@ -13,10 +13,18 @@ module Cre
13
13
  # The dig method here is just an aesthetic thing to keep us in context.
14
14
  # TODO: Add support for deeply nested credentials.
15
15
 
16
- def self.dig(env = Rails.env, credential)
17
- Rails.application.credentials.dig(
18
- env.to_sym,
19
- credential.to_sym
20
- )
16
+ def self.dig(*credentials)
17
+ env, credentials = if defined_environments.include? credentials[0].to_sym
18
+ [credentials[0].to_sym, credentials[1..-1].flatten.map(&:to_sym)]
19
+ else
20
+ [Rails.env.to_sym, [credentials].flatten.map(&:to_sym)]
21
+ end
22
+ Rails.application.credentials.dig(env, *credentials)
23
+ end
24
+
25
+ private
26
+
27
+ def self.defined_environments
28
+ Dir.entries(Rails.root.join('config','environments').to_s).grep(/\.rb$/).map{ |filename| File.basename(filename, '.rb').to_sym }
21
29
  end
22
30
  end
data/lib/cre/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cre
2
- VERSION = '2'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cre
3
3
  version: !ruby/object:Gem::Version
4
- version: '2'
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khalil Gharbaoui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2021-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.7.7
146
+ rubygems_version: 3.0.8
148
147
  signing_key:
149
148
  specification_version: 4
150
149
  summary: Fetch rails credentials the easy way!