envied 0.10.0 → 1.0.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: 0511e3b0eba9370a6b0bd51ef3a3642bbfafa30f12b92a5a007b5ce2293b3c14
4
- data.tar.gz: 62100f8640f1b5fc14ac46e8d5a916cf5ba2d3c3f7b14c99a246d06e3482a551
3
+ metadata.gz: 4c89d26111e6602a893f100be175cf566d663f8b03cb3ca6c611ba45946dd8b3
4
+ data.tar.gz: ac3a0f53199ff5410a015ea54567c7f634e07f89e47fe24627a61a80fda6d94e
5
5
  SHA512:
6
- metadata.gz: f92d02db070a5bc4f600ccc360c5d41af97c4766e537d3d29880944b45a7e8d7357d5bf01ea16d9167c1cab44398e14db2e4d7691de9c6e622f6035a322d27dc
7
- data.tar.gz: 2ccb1f56a3a626d1177a9a27829e718c344ada5293dd12dd4577d384efd030219adfed807f7f9615f456307c89a7f6f8fe308ea70f2e5d720c6500864b643b8e
6
+ metadata.gz: d2fa4e30dfcf94c8ba245dee67df569e7e413200e5cda7ab37f12c4031cb8a1e7cd889f56cab79198fd0648c0143d658a3a394345c721596495f1c3b0689aefb
7
+ data.tar.gz: f467aa666631da78d11758304adaec9eb170489ae2d8845319e9ddf4b5d04af9f41e70f37e4bd48f3918955038214ec386735b27fa8b95a3e9e18dc32bb6fbd6
data/README.md CHANGED
@@ -8,7 +8,6 @@ For the rationale behind this project, see this [blogpost](http://www.gertgoet.c
8
8
 
9
9
  * check for presence and correctness of ENV-variables
10
10
  * access to typed ENV-variables (integers, booleans etc. instead of just strings)
11
- * check the presence and correctness of a Heroku config
12
11
 
13
12
  ## Contents
14
13
 
@@ -19,8 +18,6 @@ For the rationale behind this project, see this [blogpost](http://www.gertgoet.c
19
18
  * [Groups](#groups)
20
19
  * [Defaults](#defaults)
21
20
  * [More examples](#more-examples)
22
- * [Command-line interface](#command-line-interface)
23
- * [How do I...?](#how-do-i)
24
21
  * [Development](#development)
25
22
 
26
23
  ## Quickstart
@@ -183,58 +180,6 @@ As a rule of thumb you should only use defaults:
183
180
  * See the [examples](/examples)-folder for a more extensive Envfile
184
181
  * See [the Envfile](https://github.com/eval/bunny_drain/blob/c54d7d977afb5e23a92da7a2fd0d39f6a7e29bf1/Envfile) for the bunny_drain application
185
182
 
186
- ## Command-line interface
187
-
188
- For help on a specific command, use `envied help <command>`.
189
-
190
- ```bash
191
- $ envied help
192
- Commands:
193
- envied check # Checks whether you environment contains required variables
194
- envied check:heroku # Checks whether a Heroku config contains required variables
195
- envied check:heroku:binstub # Generates a shell script for the check:heroku-task
196
- envied extract # Grep code to find ENV-variables
197
- envied help [COMMAND] # Describe available commands or one specific command
198
- envied init # Generates a default Envfile in the current working directory
199
- envied init:rails # Generate all files needed for a Rails project
200
- envied version, --version, -v # Shows version number
201
- ```
202
-
203
- ## How do I
204
-
205
- ### ...find all ENV-variables my app is currently using?
206
-
207
- ```
208
- $ bundle exec envied extract
209
- ```
210
-
211
- This comes in handy when you're not using ENVied yet. It will find all `ENV['KEY']` and `ENV.fetch('KEY')` statements in your project.
212
-
213
- It assumes a standard project layout (see the default value for the globs-option).
214
-
215
- ### ...check the config of a Heroku app?
216
-
217
- The easiest/quickest is to run:
218
-
219
- ```
220
- $ heroku config --json | bundle exec envied check:heroku
221
- ```
222
-
223
- This is equivalent to having the heroku config as your local environment and running `envied check:heroku --groups default production`.
224
-
225
- You want to run this right before a deploy to Heroku. This prevents that your app will crash during bootup because ENV-variables are missing from heroku config.
226
-
227
- You can turn the above into a handy binstub like so:
228
- ```
229
- $ bundle exec envied check:heroku:binstub
230
- # created bin/heroku-env-check
231
- ```
232
-
233
- This way you can do stuff like:
234
- ```
235
- $ ./bin/heroku-env-check && git push live master
236
- ```
237
-
238
183
  ## Development
239
184
 
240
185
  - `bin/setup`
@@ -1,3 +1,3 @@
1
1
  class ENVied
2
- VERSION = '0.10.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/envied.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'envied/version'
2
- require 'envied/cli'
3
2
  require 'envied/env_proxy'
4
3
  require 'envied/coercer'
5
4
  require 'envied/coercer/envied_string'
@@ -62,7 +61,7 @@ class ENVied
62
61
  if defined?(ActiveSupport::Deprecation.warn) && !required?
63
62
  ActiveSupport::Deprecation.warn(<<~MSG)
64
63
  It's no longer recommended to `ENVied.require` within ENVied.springify's
65
- block. Please re-run `envied init:rails` to upgrade.
64
+ block.
66
65
  MSG
67
66
  end
68
67
  if spring_enabled?
metadata CHANGED
@@ -1,61 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
8
8
  - Javier Julio
9
9
  autorequire:
10
- bindir: exe
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2024-08-09 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: thor
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0.15'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '2.0'
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: '0.15'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
12
+ date: 2024-08-17 00:00:00.000000000 Z
13
+ dependencies: []
34
14
  description: Ensure presence and type of your app's ENV-variables.
35
15
  email:
36
16
  - gert@thinkcreate.nl
37
17
  - jjfutbol@gmail.com
38
- executables:
39
- - envied
18
+ executables: []
40
19
  extensions: []
41
20
  extra_rdoc_files: []
42
21
  files:
43
22
  - LICENSE.txt
44
23
  - README.md
45
- - exe/envied
46
24
  - lib/envied.rb
47
- - lib/envied/cli.rb
48
25
  - lib/envied/coercer.rb
49
26
  - lib/envied/coercer/envied_string.rb
50
27
  - lib/envied/configuration.rb
51
28
  - lib/envied/env_proxy.rb
52
- - lib/envied/env_var_extractor.rb
53
29
  - lib/envied/variable.rb
54
30
  - lib/envied/version.rb
55
31
  homepage: https://github.com/javierjulio/envied
56
32
  licenses:
57
33
  - MIT
58
- metadata: {}
34
+ metadata:
35
+ homepage_uri: https://github.com/javierjulio/envied
36
+ source_code_uri: https://github.com/javierjulio/envied.git
37
+ bug_tracker_uri: https://github.com/javierjulio/envied/issues
38
+ changelog_uri: https://github.com/javierjulio/envied/blob/master/CHANGELOG.md
39
+ wiki_uri: https://github.com/javierjulio/envied/wiki
40
+ rubygems_mfa_required: 'true'
59
41
  post_install_message:
60
42
  rdoc_options: []
61
43
  require_paths:
data/exe/envied DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'envied'
3
-
4
- ENVied::Cli.start
data/lib/envied/cli.rb DELETED
@@ -1,130 +0,0 @@
1
- require 'thor'
2
- require 'json'
3
- require 'envied/env_var_extractor'
4
-
5
- class ENVied
6
- class Cli < Thor
7
- include Thor::Actions
8
- source_root File.expand_path('../templates', __FILE__)
9
-
10
- desc "version, --version, -v", "Shows version number"
11
- def version
12
- puts ENVied::VERSION
13
- end
14
- map %w(-v --version) => :version
15
-
16
- desc "extract", "Grep code to find ENV-variables"
17
- long_desc <<-LONG
18
- Greps source-files to find all ENV-variables your code is using.
19
-
20
- This task helps you find variables to put in your Envfile.
21
-
22
- By default the test/spec-folders are excluded. Use `--tests` to include them.
23
- LONG
24
- option :globs, type: :array, default: ENVied::EnvVarExtractor.defaults[:globs], banner: "*.* lib/*"
25
- option :tests, type: :boolean, default: false, desc: "include tests/specs"
26
- def extract
27
- globs = options[:globs]
28
- globs << "{test,spec}/*" if options[:tests]
29
- var_occurrences = ENVied::EnvVarExtractor.new(globs: globs).extract
30
-
31
- puts "Found %d occurrences of %d variables:" % [var_occurrences.values.flatten.size, var_occurrences.size]
32
- var_occurrences.sort.each do |var, occs|
33
- puts var
34
- occs.sort_by{|i| i[:path].size }.each do |occ|
35
- puts "* %s:%s" % occ.values_at(:path, :line)
36
- end
37
- puts
38
- end
39
- end
40
-
41
- desc "init", "Generates a default Envfile in the current working directory"
42
- def init
43
- puts "Writing Envfile to #{File.expand_path('Envfile')}"
44
- template("Envfile.tt")
45
-
46
- puts "Add the following snippet (or similar) to your app's initialization:"
47
- puts "ENVied.require(*ENV['ENVIED_GROUPS'] || [:default, ENV['RACK_ENV']])"
48
- end
49
-
50
- desc "init:rails", "Generate all files needed for a Rails project"
51
- define_method "init:rails" do
52
- puts "Writing Envfile to #{File.expand_path('Envfile')}"
53
- template("Envfile.tt")
54
- inject_into_file "config/application.rb", "\nENVied.require(*ENV['ENVIED_GROUPS'] || Rails.groups)", after: /^ *Bundler.require.+$/
55
- legacy_initializer = Dir['config/initializers/*envied*.rb'].first
56
- if legacy_initializer && File.exists?(legacy_initializer)
57
- puts "Removing 'ENVied.require' from #{legacy_initializer.inspect}."
58
- puts "(you might want to remove the whole file)"
59
- comment_lines legacy_initializer, /ENVied.require/
60
- end
61
- end
62
-
63
- desc "check", "Checks whether you environment contains required variables"
64
- long_desc <<-LONG
65
- Checks whether required variables are present and valid in your shell.
66
-
67
- On success the process will exit with status 0.
68
- Else the missing/invalid variables will be shown, and the process will exit with status 1.
69
- LONG
70
- option :groups, type: :array, desc: "uses ENV['ENVIED_GROUPS'] as default if present", default: ENV['ENVIED_GROUPS'] || %w(default), banner: 'default production'
71
- option :quiet, type: :boolean, desc: 'Communicate success of the check only via the exit status.'
72
- def check
73
- ENVied.require(*options[:groups])
74
- unless options[:quiet]
75
- puts "All variables for group(s) #{options[:groups]} are present and valid"
76
- end
77
- end
78
-
79
- desc "check:heroku", "Checks whether a Heroku config contains required variables"
80
- long_desc <<-LONG
81
- Checks the config of your Heroku app against the local Envfile.
82
-
83
- The Heroku config should be piped to this task:
84
-
85
- heroku config --json | bundle exec envied check:heroku
86
-
87
- Use the check:heroku:binstub-task to turn this into a bash-script.
88
-
89
- On success the process will exit with status 0.
90
- Else the missing/invalid variables will be shown, and the process will exit with status 1.
91
- LONG
92
- option :groups, type: :array, default: %w(default production), banner: 'default production'
93
- option :quiet, type: :boolean, desc: 'Communicate success of the check only via the exit status.'
94
- define_method "check:heroku" do
95
- if STDIN.tty?
96
- error "Please pipe to this task i.e. `heroku config --json | bundle exec envied check:heroku`"
97
- exit 1
98
- end
99
- heroku_env = JSON.parse(STDIN.read)
100
- ENV.replace(heroku_env)
101
-
102
- requested_groups = ENV['ENVIED_GROUPS'] || options[:groups]
103
- ENVied.require(*requested_groups)
104
- unless options[:quiet]
105
- puts "All variables for group(s) #{requested_groups} are present and valid in your Heroku app"
106
- end
107
- end
108
-
109
- desc "check:heroku:binstub", "Generates a shell script for the check:heroku-task"
110
- long_desc <<-LONG
111
- Generates a shell script to check the Heroku config against the local Envfile.
112
-
113
- The same as the check:heroku-task, but all in one script (no need to pipe `heroku config --json` to it etc.).
114
- LONG
115
- option :dest, banner: "where to put the script", desc: "Default: bin/<app>-env-check or bin/heroku-env-check"
116
- option :app, banner: "name of Heroku app", desc: "uses ENV['HEROKU_APP'] as default if present", default: ENV['HEROKU_APP']
117
- option :groups, type: :array, default: %w(default production), banner: 'default production'
118
- define_method "check:heroku:binstub" do
119
- require 'fileutils'
120
- @app = options[:app]
121
- @dest = options[:dest]
122
- @dest ||= File.join(*%W(bin #{(@app || 'heroku')}-env-check))
123
- @groups = options[:groups]
124
-
125
- full_dest = File.expand_path(@dest)
126
- template("heroku-env-check.tt", full_dest)
127
- FileUtils.chmod 0755, full_dest
128
- end
129
- end
130
- end
@@ -1,76 +0,0 @@
1
- class ENVied
2
- class EnvVarExtractor
3
- def self.defaults
4
- @defaults ||= begin
5
- {
6
- extensions: %w(ru thor rake rb yml ruby yaml erb builder markerb haml),
7
- globs: %w(*.* Thorfile Rakefile {app,config,db,lib,script}/*)
8
- }
9
- end
10
- end
11
-
12
- def defaults
13
- self.class.defaults
14
- end
15
-
16
- attr_reader :globs, :extensions
17
-
18
- def initialize(**options)
19
- @globs = options.fetch(:globs, self.defaults[:globs])
20
- @extensions = options.fetch(:extensions, self.defaults[:extensions])
21
- end
22
-
23
- def self.extract_from(globs, **options)
24
- new(options.merge(globs: Array(globs))).extract
25
- end
26
-
27
- # Greps all ENV-variables from a line of text.
28
- # Captures 'A' in lines like `ENV['A']`, but also `ENV.fetch('A')`.
29
- #
30
- # @param line [String] the line to grep
31
- #
32
- # @example
33
- # extractor.new.capture_variables("config.force_ssl = ENV['FORCE_SSL']")
34
- # # => ["FORCE_SSL"]
35
- #
36
- # @return [Array<String>] the names o
37
- def capture_variables(line)
38
- line.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten
39
- end
40
-
41
- # Extract all keys recursively from files found via `globs`.
42
- # Any occurrence of `ENV['A']` or `ENV.fetch('A')`, will result
43
- # in 'A' being extracted.
44
- #
45
- # @param globs [Array<String>] the collection of globs
46
- #
47
- # @example
48
- # EnvVarExtractor.new.extract(*%w(app lib))
49
- # # => {'A' => [{:path => 'app/models/user.rb', :line => 2}, {:path => ..., :line => ...}],
50
- # 'B' => [{:path => 'config/application.rb', :line => 12}]}
51
- #
52
- # @return [<Hash{String => Array<String => Array>}>] the list of items.
53
- def extract(globs = self.globs)
54
- results = Hash.new { |hash, key| hash[key] = [] }
55
-
56
- Array(globs).each do |glob|
57
- Dir.glob(glob).each do |item|
58
- next if File.basename(item)[0] == ?.
59
-
60
- if File.directory?(item)
61
- results.merge!(extract("#{item}/*"))
62
- else
63
- next unless extensions.detect {|ext| File.extname(item)[ext] }
64
- File.readlines(item).each_with_index do |line, ix|
65
- capture_variables(line).each do |variable|
66
- results[variable] << { :path => item, :line => ix.succ }
67
- end
68
- end
69
- end
70
- end
71
- end
72
-
73
- results
74
- end
75
- end
76
- end