cre 2.1.1 → 2.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d91d919864b358dde52a257c05173cbad5fa6c6cac3e86b8d4cd1a385e4cd3a
4
- data.tar.gz: 82534e175f6143a208468c4099f39d604c794bd0a38c6572bad3eafddb3899a1
3
+ metadata.gz: bb52087e9fb45f42d863d667afc789134168639efb231eae6a15f8a3572ea437
4
+ data.tar.gz: 10338d5b5b3dc14f795c465c878738e0291138814b11250938c177505c73abe4
5
5
  SHA512:
6
- metadata.gz: b486fad7bdd65a0ee6775cada2d5fb5e388b8fd16838d7282df2e47007a0538236386996c2b7098091930ae0c4e07d3329414b8f486f931d1a39692f133eeb00
7
- data.tar.gz: 86e71dda670c771c227cd090e4c97bfa3a38ac82785532718fa02766c3cd4e78caf73f81fd32b9fc159942e4b26f9816c0910d89eab2e5d4d20db04f57580e42
6
+ metadata.gz: 9e533e147486fe87264e81e7973fc5aa8fbe17d3a406e5c4a3704b209614e370ecdaa8b34814112cbc016288574b08e1753fa4ffd15d656834fd358f359d4539
7
+ data.tar.gz: 49e692e14c9d35fa5c9d70a4f4b1f23fc157f2d3aefb79dcc80782a7fe87097651a11d3f5f981d97a25490a3f76663192448488bd4488ebe85116e7d6cb49694
data/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ ## 2.2.0 (2026-08-02)
4
+
5
+ No API changes. `Cre.dig` behaves exactly as before.
6
+
7
+ ### Changed
8
+
9
+ - **Removed the `rails` runtime dependency.** Cre only ever touches
10
+ `Rails.application` at call time, inside your Rails app, where Rails is
11
+ already loaded. The gem now declares no runtime dependencies at all, so it
12
+ no longer constrains the Rails version in your bundle. Cre continues to
13
+ work on Rails 5.2 through 8.x (CI covers 6.1 through 8.1).
14
+ - `Cre::Railtie` (an empty class) is no longer loaded by default. The
15
+ constant is still defined when Rails is present, for backward
16
+ compatibility, and will be removed in 3.0.
17
+ - `Cre.defined_environments` is now memoized and uses `Dir.glob`, so it no
18
+ longer re-reads the directory on every call and no longer raises if
19
+ `config/environments` is missing.
20
+
21
+ ### Added
22
+
23
+ - `Cre::Error` is raised with a clear message when `Cre.dig` is called
24
+ outside a booted Rails application (previously a bare `NameError`).
25
+ - `Cre.dig` with no arguments now returns `nil` (previously raised
26
+ `NoMethodError`).
27
+ - CI on GitHub Actions across Ruby 2.7-3.4 and Rails 6.1-8.1 (replaces
28
+ Travis).
29
+
30
+ ### Housekeeping
31
+
32
+ - `Gemfile.lock`, `coverage/` and `.rspec_status` are no longer committed;
33
+ this also retires the long queue of automated lockfile security PRs,
34
+ which only ever flagged the development dependencies of the test app.
35
+ - The spec dummy app boots on railties alone (no more ActiveRecord/sqlite3
36
+ in the development dependencies).
37
+ - Gemspec metadata added (`changelog_uri`, `source_code_uri`,
38
+ `required_ruby_version >= 2.7`, `rubygems_mfa_required`).
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Khalil Gharbaoui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- [![Build Status](https://travis-ci.org/khalilgharbaoui/cre.svg?branch=master)](https://travis-ci.org/khalilgharbaoui/cre) [![Gem Version](https://badge.fury.io/rb/cre.svg)](https://badge.fury.io/rb/cre)
1
+ [![CI](https://github.com/khalilgharbaoui/cre/actions/workflows/ci.yml/badge.svg)](https://github.com/khalilgharbaoui/cre/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/cre.svg)](https://badge.fury.io/rb/cre)
2
+
2
3
  # Cre
4
+
3
5
  This gem basically lets you dig out the rails encrypted credentials by simply doing:
4
6
 
5
7
  `Cre.dig(:password)` ✅
@@ -8,15 +10,17 @@ Instead of going the long way:
8
10
 
9
11
  `Rails.application.credentials.dig(Rails.env.to_sym, :password)` ❌
10
12
 
13
+ Cre has **no runtime dependencies** and works on Rails 5.2 through 8.x.
14
+
11
15
  ## Usage
12
- By default it uses the currently active rails environment.
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`
16
+
17
+ By default it uses the currently active rails environment. Specify the environment specifically by adding it as the first argument. But do remember that it only considers `defined environments` in `config/environments`
15
18
 
16
19
  `Cre.dig(:production, :password)`
17
20
 
18
21
  ⚠️ This assumes your credentials are setup like:
19
- ```
22
+
23
+ ```yaml
20
24
  production:
21
25
  aws_key: 'somekeyproduction'
22
26
  password: 'fakepass'
@@ -26,37 +30,53 @@ development:
26
30
  test:
27
31
  aws_key: 'somekeytest'
28
32
  password: 'fakepass'
29
- ```
30
- It also supports deeper nested credentials for example:
31
33
  ```
32
- Cre.dig(:production, :aws, :client, secret, :key)
33
- ```
34
- Or:
34
+
35
+ It also supports deeper nested credentials for example:
36
+
37
+ ```ruby
38
+ Cre.dig(:production, :aws, :client, :secret, :key)
35
39
  ```
40
+
41
+ Or:
42
+
43
+ ```ruby
36
44
  Cre.dig(:something, :nested, :multiple, :layers, :deep)
37
45
  ```
46
+
47
+ ### Good to know
48
+
49
+ - Calling `Cre.dig` outside a booted Rails application raises `Cre::Error`
50
+ with a clear message.
51
+ - If a top-level credential key has the same name as one of your defined
52
+ environments (e.g. a credential literally called `production`), the first
53
+ argument is interpreted as the environment selector. Give such keys a
54
+ different name.
55
+
38
56
  ## Installation
57
+
39
58
  Add this line to your application's Gemfile:
40
59
 
41
60
  ```ruby
42
- gem 'cre', '~> 2.1.1'
61
+ gem 'cre', '~> 2.2'
43
62
  ```
44
63
 
45
64
  And then execute:
46
- ```bash
47
- $ bundle
48
- ```
65
+
66
+ $ bundle
49
67
 
50
68
  Or install it yourself as:
51
- ```bash
52
- $ gem install cre
53
- ```
54
69
 
55
- ##Todo:
56
- - Exeption handeling
70
+ $ gem install cre
71
+
72
+ ## Changelog
73
+
74
+ See [CHANGELOG.md](CHANGELOG.md).
57
75
 
58
76
  ## Contributing
77
+
59
78
  Contribution directions go here.
60
79
 
61
80
  ## License
81
+
62
82
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/cre/railtie.rb CHANGED
@@ -1,4 +1,9 @@
1
- module Cre
2
- class Railtie < ::Rails::Railtie
1
+ # Deprecated: this Railtie has always been empty and cre no longer loads it
2
+ # by default. The constant is kept so existing references keep working.
3
+ # It will be removed in cre 3.0.
4
+ if defined?(::Rails::Railtie)
5
+ module Cre
6
+ class Railtie < ::Rails::Railtie
7
+ end
3
8
  end
4
9
  end
data/lib/cre/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cre
2
- VERSION = '2.1.1'
2
+ VERSION = '2.2.0'
3
3
  end
data/lib/cre.rb CHANGED
@@ -1,7 +1,10 @@
1
- require "cre/railtie"
2
1
  require "cre/version"
2
+ require "cre/railtie" if defined?(::Rails::Railtie)
3
3
 
4
4
  module Cre
5
+ # Raised when Cre is used outside a booted Rails application.
6
+ Error = Class.new(StandardError)
7
+
5
8
  # Fetching Rails encrypted credentials with:
6
9
  # `Rails.application.credentials.dig(:environment, :credential)`
7
10
  # Is too long for my taste.
@@ -11,9 +14,11 @@ module Cre
11
14
  # specified and it is called with the credential only:
12
15
  # `Cre.dig(:password)`
13
16
  # The dig method here is just an aesthetic thing to keep us in context.
14
- # TODO: Add support for deeply nested credentials.
15
17
 
16
18
  def self.dig(*credentials)
19
+ ensure_rails_application!
20
+ return nil if credentials.empty?
21
+
17
22
  env, credentials = if defined_environments.include? credentials[0].to_sym
18
23
  [credentials[0].to_sym, credentials[1..-1].flatten.map(&:to_sym)]
19
24
  else
@@ -22,9 +27,20 @@ module Cre
22
27
  Rails.application.credentials.dig(env, *credentials)
23
28
  end
24
29
 
25
- private
30
+ def self.ensure_rails_application!
31
+ return if defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
32
+
33
+ raise Error, "Cre requires a booted Rails application " \
34
+ "(Rails.application is not available)."
35
+ end
36
+ private_class_method :ensure_rails_application!
26
37
 
38
+ # NOTE: kept public for backward compatibility - the historic `private`
39
+ # keyword never applied to `def self.` methods, so this was always
40
+ # callable.
27
41
  def self.defined_environments
28
- Dir.entries(Rails.root.join('config','environments').to_s).grep(/\.rb$/).map{ |filename| File.basename(filename, '.rb').to_sym }
42
+ @defined_environments ||=
43
+ Dir.glob(Rails.root.join("config", "environments", "*.rb"))
44
+ .map { |filename| File.basename(filename, ".rb").to_sym }
29
45
  end
30
46
  end
metadata CHANGED
@@ -1,105 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cre
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khalil Gharbaoui
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-12-17 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '5.2'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '5.2'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0.11'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0.11'
41
- - !ruby/object:Gem::Dependency
42
- name: awesome_print
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '1.8'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '1.8'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '3.8'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '3.8'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0.10'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0.10'
83
- - !ruby/object:Gem::Dependency
84
- name: sqlite3
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.4'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 1.4.2
93
- type: :development
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '1.4'
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 1.4.2
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
103
12
  description: "Cre reduces the amount of code you have to write when fetching
104
13
  rails credentials. If your encrypted credentials look like
105
14
  this:\n\n production:\n password: 'foobar'\n
@@ -116,19 +25,22 @@ executables: []
116
25
  extensions: []
117
26
  extra_rdoc_files: []
118
27
  files:
119
- - MIT-LICENSE
28
+ - CHANGELOG.md
29
+ - LICENSE.txt
120
30
  - README.md
121
- - Rakefile
122
31
  - lib/cre.rb
123
32
  - lib/cre/railtie.rb
124
33
  - lib/cre/version.rb
125
- - lib/tasks/cre_tasks.rake
126
34
  homepage: https://github.com/khalilgharbaoui/cre
127
35
  licenses:
128
36
  - MIT
129
37
  metadata:
130
38
  allowed_push_host: https://rubygems.org
131
- post_install_message:
39
+ homepage_uri: https://github.com/khalilgharbaoui/cre
40
+ source_code_uri: https://github.com/khalilgharbaoui/cre
41
+ changelog_uri: https://github.com/khalilgharbaoui/cre/blob/master/CHANGELOG.md
42
+ bug_tracker_uri: https://github.com/khalilgharbaoui/cre/issues
43
+ rubygems_mfa_required: 'true'
132
44
  rdoc_options: []
133
45
  require_paths:
134
46
  - lib
@@ -136,15 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
48
  requirements:
137
49
  - - ">="
138
50
  - !ruby/object:Gem::Version
139
- version: '0'
51
+ version: '2.7'
140
52
  required_rubygems_version: !ruby/object:Gem::Requirement
141
53
  requirements:
142
54
  - - ">="
143
55
  - !ruby/object:Gem::Version
144
56
  version: '0'
145
57
  requirements: []
146
- rubygems_version: 3.1.2
147
- signing_key:
58
+ rubygems_version: 4.0.12
148
59
  specification_version: 4
149
60
  summary: Fetch rails credentials the easy way!
150
61
  test_files: []
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2018 Khalil Gharbaoui
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Cre'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
- require 'bundler/gem_tasks'
18
-
19
- require 'rake/testtask'
20
-
21
- Rake::TestTask.new(:test) do |t|
22
- t.libs << 'test'
23
- t.pattern = 'test/**/*_test.rb'
24
- t.verbose = false
25
- end
26
-
27
- task default: :test
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :cre do
3
- # # Task goes here
4
- # end