cre 0.1.3 → 2.1.1

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 +10 -2
  3. data/lib/cre/version.rb +1 -1
  4. data/lib/cre.rb +13 -5
  5. metadata +20 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93b74a28930e320c89007dbd79b5d085bd8bcb577bcba60e28a4d500505e95da
4
- data.tar.gz: 13be234c8bb38b25a8d630c10f5bf0a3781b647dd727e74bc171178aec5b97eb
3
+ metadata.gz: 6d91d919864b358dde52a257c05173cbad5fa6c6cac3e86b8d4cd1a385e4cd3a
4
+ data.tar.gz: 82534e175f6143a208468c4099f39d604c794bd0a38c6572bad3eafddb3899a1
5
5
  SHA512:
6
- metadata.gz: 8cf28c23b5d14718e2552774c0046d1b255367a69c28f5e6508802f5208839ca5c516b9e012afa8a5ffec7779c0c1f1a83f301de6a5d3047ec8d9bfaf5289315
7
- data.tar.gz: 981df0ba3552482150b9bfd7bffe68d4dbb9b17b776467b08946fc81a995e724f5ab7187242e585686ce56eff7b2bf4cf15085a60e3bd0386c475859ceb6983b
6
+ metadata.gz: b486fad7bdd65a0ee6775cada2d5fb5e388b8fd16838d7282df2e47007a0538236386996c2b7098091930ae0c4e07d3329414b8f486f931d1a39692f133eeb00
7
+ data.tar.gz: 86e71dda670c771c227cd090e4c97bfa3a38ac82785532718fa02766c3cd4e78caf73f81fd32b9fc159942e4b26f9816c0910d89eab2e5d4d20db04f57580e42
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,12 +26,20 @@ 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:
31
40
 
32
41
  ```ruby
33
- gem 'cre', '~> 0.1.2'
42
+ gem 'cre', '~> 2.1.1'
34
43
  ```
35
44
 
36
45
  And then execute:
@@ -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/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cre
2
- VERSION = '0.1.3'
2
+ VERSION = '2.1.1'
3
3
  end
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
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khalil Gharbaoui
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-02 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.11'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: awesome_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.8'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.10'
83
83
  - !ruby/object:Gem::Dependency
@@ -86,20 +86,20 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.3'
89
+ version: '1.4'
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 1.3.13
92
+ version: 1.4.2
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '1.3'
99
+ version: '1.4'
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 1.3.13
102
+ version: 1.4.2
103
103
  description: "Cre reduces the amount of code you have to write when fetching
104
104
  rails credentials. If your encrypted credentials look like
105
105
  this:\n\n production:\n password: 'foobar'\n
@@ -128,7 +128,7 @@ licenses:
128
128
  - MIT
129
129
  metadata:
130
130
  allowed_push_host: https://rubygems.org
131
- post_install_message:
131
+ post_install_message:
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -143,9 +143,8 @@ 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.6
148
- signing_key:
146
+ rubygems_version: 3.1.2
147
+ signing_key:
149
148
  specification_version: 4
150
149
  summary: Fetch rails credentials the easy way!
151
150
  test_files: []