envdocs 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9da113a4d5f4deb3f456ec4b964af5bab94de452f0672607bf0f60054a8d9b5
4
+ data.tar.gz: 96418182334564c323a009d4753a47e836891329c6c2f4aa4af837e877a88dbb
5
+ SHA512:
6
+ metadata.gz: 22f5cb72671e016f3c7836e7b5b5ecae59aa727f900a99a1255b4d733b8c8830913d568835c7d22e67a3b1219d536b8adc04f231f46ec6c06f28191f1dcd238c
7
+ data.tar.gz: 7feb5f0a2a18419e6c8d45bf3583c7df365c71d932a01447de78ef7b4855684ba72b9841803c8da04e8ac13acce8d73651fd75dfc00de3f361cbe4132ebfca34
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) Joseph James Rodriguez
2
+
3
+ EnvDocs is an Open Source project licensed under the terms of
4
+ the LGPLv3 license. Please see <https://www.gnu.org/licenses/lgpl-3.0.txt>
5
+ for license text.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Envdocs
2
+ Simple and Lightweight Gem to handle Environment(ENV) variable sanity-checks and documentation. Providing teams with the ability to sanity-check their expected loaded ENV variables at any point.
3
+
4
+ Every team documents, stores and persists ENV variables differently. One of the most draining experiences for a team is forgetting to update an ENV key for an environment, pushing things through, and trying to understand why things aren't working. This gem aims to fix that.
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'envdocs'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install envdocs
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ 1. Create a `sample_keys.yml` file in your application's `config` directory:
26
+ Example:
27
+ ```yaml
28
+ - development:
29
+ - key: RAILS_ENV
30
+ description: Provides info on the rails env
31
+ required: true
32
+ - key: FOO
33
+ description: Testing
34
+ required: false
35
+ - test:
36
+ - key: RAILS_ENV
37
+ description: Provides info on the rails env
38
+ required: true
39
+ ```
40
+ The top-level key denotes the environment name we'd like to check against(ie. development, test, etc...). The nested objects each represent a key we'd like to validate for that environment.
41
+
42
+ 2. Initialize the gem by pointing it to your `sample_keys.yml` file in your application's `./config` folder.
43
+ ```ruby
44
+ # initializers/envdocs.rb
45
+ Envdocs.configure(
46
+ filename: 'sample_keys.yml',
47
+ environment: Rails.env,
48
+ opts: { include_optional: false }
49
+ )
50
+ ```
51
+
52
+ 3. Anywhere in your code that you'd like to validate the proper keys exist, call:
53
+ ```ruby
54
+ Envdocs.find_missing_keys
55
+ ```
56
+
57
+ When called, an array of strings will be returned containing any missing keys. If no keys are missing, an empty array will be returned.
58
+
59
+ ## Contributing
60
+ Features, bug fixes and other changes to envdocs-ruby are gladly accepted. Please open issues or a pull request with your change.
61
+
62
+ ## License
63
+ The gem is available as open source under the terms of the [LGPLv3 License](https://www.gnu.org/licenses/lgpl-3.0.html).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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 = 'Envdocs'
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
data/lib/envdocs.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'envdocs/railtie'
2
+
3
+ module Envdocs
4
+ class << self
5
+ attr_reader :environment, :filename, :opts
6
+
7
+ # @param [String] filename
8
+ # @param [String] environment
9
+ # @param [Hash] opts
10
+ # => [Booleam] include_optional
11
+ def configure(filename:, environment:, opts: {})
12
+ @configured = true
13
+ @environment = environment
14
+ @filename = filename
15
+ @opts = opts
16
+ @sampler = Sampler.new(filename, environment)
17
+ end
18
+
19
+ # Returns an array of keys that were not found in the current ENV
20
+ # @return [Array[String]]
21
+ def find_missing_keys
22
+ unless @configured
23
+ raise StandardError, 'Envdocs environment must be configured before running this command'
24
+ end
25
+
26
+ # If optionals included, return all.
27
+ # Otherwise, return only keys that are marked as required.
28
+ result = {}
29
+ keys_to_search = @sampler.env_keys.select { |ek| @opts[:include_optional] || ek['required'] }
30
+
31
+ keys_to_search.each { |ek| result[ek['key']] = ENV.fetch(ek['key'], nil) }
32
+
33
+ result.reject { |k,v| !v.nil? }.keys
34
+ end
35
+ end
36
+
37
+ # Retrieves keys for an environment from a sample template
38
+ class Sampler
39
+ attr_reader :filename, :template, :curr_env, :env_keys
40
+
41
+ # @param [String] filename
42
+ # @param [String] curr_env
43
+ def initialize(filename, curr_env)
44
+ @filename = filename
45
+ @curr_env = curr_env
46
+ @template = retrieve_keys_template(filename)
47
+ @env_keys = retrieve_keys_for_env_from_template(curr_env)
48
+ end
49
+
50
+ private
51
+
52
+ # @param [String] filename
53
+ def retrieve_keys_template(filename)
54
+ YAML.load(File.read(Rails.root.join('config', filename)))
55
+ end
56
+
57
+ # @param [String] curr_env
58
+ # @return [Array[Hash]]
59
+ def retrieve_keys_for_env_from_template(curr_env)
60
+ @template.find { |k| k[curr_env].present? }[curr_env]
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,4 @@
1
+ module Envdocs
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Envdocs
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envdocs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph James Rodriguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-12 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: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Envdocs allows you to find missing env keys, as well as create living
48
+ documentation of the keys themselves.
49
+ email:
50
+ - joerodrig3@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/envdocs.rb
59
+ - lib/envdocs/railtie.rb
60
+ - lib/envdocs/version.rb
61
+ homepage: https://github.com/joerodrig/envdocs-ruby/
62
+ licenses:
63
+ - LGPLv3
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.1.4
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Find missing ENV keys
84
+ test_files: []