envied 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +78 -22
- data/lib/envied.rb +12 -0
- data/lib/envied/cli.rb +6 -0
- data/lib/envied/templates/Envfile.tt +4 -0
- data/lib/envied/templates/rails-initializer.tt +5 -0
- data/lib/envied/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46ff25f0ca1accf79ba7095db2e6b0232af3cb8c
|
4
|
+
data.tar.gz: f6f3572cb136f9d3e68affbfa4bafa839a203b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70d6e4d6fb890c88bbb18c058c487e4c9bedcc0183562e6ef466f54c96c82701f635a2b7aa0af7da32747938ba14caea1098200cbd94a9d43068d9e3d54c8f14
|
7
|
+
data.tar.gz: a25bdf917df7f8479733e751051a08c9289c6c8beb8acc9c9068ff5b095e33c80c03e8e473e43c1f48083cddf6e8b41dfe94a82a38050d793db49e6d8edb1be8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,25 @@
|
|
2
2
|
|
3
3
|
### TL;DR ensure presence and type of your app's ENV-variables.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
5
|
+
Features:
|
6
|
+
|
7
|
+
* check for presence and correctness of ENV-variables
|
8
|
+
* access to typed ENV-variables (integers, booleans etc. instead of just strings)
|
9
|
+
* check the presence and correctness of Heroku config
|
10
|
+
|
11
|
+
## Contents
|
12
|
+
|
13
|
+
* [Quickstart](#quickstart)
|
14
|
+
* [Installation](#installation)
|
15
|
+
* [Configuration](#configuration)
|
16
|
+
* [Types](#types)
|
17
|
+
* [Groups](#groups)
|
18
|
+
* [Defaults](#defaults)
|
19
|
+
* [Rails](#rails)
|
20
|
+
* [Command-line interface](#command-line-interface)
|
21
|
+
* [Testing](#testing)
|
22
|
+
* [Developing](#developing)
|
23
|
+
* [Contributing](#contributing)
|
10
24
|
|
11
25
|
## Quickstart
|
12
26
|
|
@@ -23,7 +37,7 @@ variable :PORT, :Integer
|
|
23
37
|
### 2) Check for presence and coercibility
|
24
38
|
|
25
39
|
```ruby
|
26
|
-
#
|
40
|
+
# during initialization
|
27
41
|
ENVied.require
|
28
42
|
```
|
29
43
|
|
@@ -40,6 +54,24 @@ ENVied.PORT # => 3001
|
|
40
54
|
ENVied.FORCE_SSL # => false
|
41
55
|
```
|
42
56
|
|
57
|
+
## Installation
|
58
|
+
|
59
|
+
Add this line to your application's Gemfile:
|
60
|
+
|
61
|
+
gem 'envied'
|
62
|
+
|
63
|
+
...then bundle:
|
64
|
+
|
65
|
+
$ bundle
|
66
|
+
|
67
|
+
...then for Rails applications:
|
68
|
+
|
69
|
+
$ bundle exec envied init:rails
|
70
|
+
|
71
|
+
...or for non-Rails applications:
|
72
|
+
|
73
|
+
$ bundle exec envied init
|
74
|
+
|
43
75
|
## Configuration
|
44
76
|
|
45
77
|
### Types
|
@@ -154,7 +186,45 @@ ENVied.require(:default, :test, :ci)
|
|
154
186
|
ENVied.require(:default, ENV['RACK_ENV'], (ENV['CI'] ? :ci : :not_ci))
|
155
187
|
```
|
156
188
|
|
157
|
-
##
|
189
|
+
## Rails
|
190
|
+
|
191
|
+
**tl;dr** use the `init:rails`-task to generate the necessary files for a Rails app (see [installation](#installation)).
|
192
|
+
|
193
|
+
---
|
194
|
+
|
195
|
+
With the [Spring](https://github.com/rails/spring) preloader (which is part of the default Rails setup nowadays) it's a bit tricky when to do `ENVied.require`.
|
196
|
+
|
197
|
+
The first time you execute a command (say `bin/rails console`), Spring will start the server from which subsequent commands fork from.
|
198
|
+
Currently [a bug in Spring](https://github.com/rails/spring/pull/267#issue-28580171) causes the initialization of the forked process to use the server's `ENV` instead of the actual `ENV`.
|
199
|
+
|
200
|
+
So if your `ENV` is not valid the first time you start Spring...:
|
201
|
+
|
202
|
+
# spring server *not* running
|
203
|
+
$ bin/rails console
|
204
|
+
# spring server started
|
205
|
+
# error raised: Please set the following ENV-variables: FORCE_SSL (RuntimeError)
|
206
|
+
|
207
|
+
...it won't be valid for subsequent commands (even when you provide the correct variables):
|
208
|
+
|
209
|
+
# spring server still running
|
210
|
+
# FORCE_SSL=1 bin/rails console
|
211
|
+
# error raised: Please set the following ENV-variables: FORCE_SSL (RuntimeError)
|
212
|
+
|
213
|
+
So while doing a `ENVied.require` in `config/application.rb` would seem perfectly fine, it won't work in the default 'springified' Rails setup.
|
214
|
+
|
215
|
+
The workaround (which the `init:rails`-task will generate) is to move the `ENVied.require` to Spring's `after_fork`-callback.
|
216
|
+
If you want to change Rails' config based on ENV-variables you should put this in an `after_fork`-callback as well:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
# config/initializers/envied.rb as generated by 'bundle exec envied init:rails'
|
220
|
+
ENVied.springify do
|
221
|
+
ENVied.require(:default, ENV['RAILS_ENV'])
|
222
|
+
|
223
|
+
Rails.configuration.force_ssl = ENVied.FORCE_SSL
|
224
|
+
end
|
225
|
+
```
|
226
|
+
|
227
|
+
## Command-line interface
|
158
228
|
|
159
229
|
```bash
|
160
230
|
$ envied help
|
@@ -164,22 +234,9 @@ Commands:
|
|
164
234
|
envied check:heroku:binstub # Generates a shell script for the check:heroku-task
|
165
235
|
envied help [COMMAND] # Describe available commands or one specific command
|
166
236
|
envied init # Generates a default Envfile in the current working directory
|
237
|
+
envied init:rails # Generate all files needed for a Rails project
|
167
238
|
```
|
168
239
|
|
169
|
-
## Installation
|
170
|
-
|
171
|
-
Add this line to your application's Gemfile:
|
172
|
-
|
173
|
-
gem 'envied'
|
174
|
-
|
175
|
-
...then bundle:
|
176
|
-
|
177
|
-
$ bundle
|
178
|
-
|
179
|
-
...and generate the `Envfile`:
|
180
|
-
|
181
|
-
$ bundle exec envied init
|
182
|
-
|
183
240
|
## Testing
|
184
241
|
|
185
242
|
```bash
|
@@ -196,7 +253,6 @@ bin/rake
|
|
196
253
|
bin/pry --gem
|
197
254
|
```
|
198
255
|
|
199
|
-
|
200
256
|
## Contributing
|
201
257
|
|
202
258
|
1. Fork it ( http://github.com/eval/envied/fork )
|
data/lib/envied.rb
CHANGED
@@ -99,6 +99,18 @@ class ENVied
|
|
99
99
|
@instance = group_configuration.new(env)
|
100
100
|
end
|
101
101
|
|
102
|
+
def self.springified_require(*args)
|
103
|
+
springify { ENVied.require(*args) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.springify(&block)
|
107
|
+
if defined?(Spring) && Spring.respond_to?(:watcher)
|
108
|
+
Spring.after_fork(&block)
|
109
|
+
else
|
110
|
+
block.call
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
102
114
|
def self.ensure_configured!
|
103
115
|
# Backward compat: load Envfile only when it's present
|
104
116
|
configure_via_envfile if envfile_exist?
|
data/lib/envied/cli.rb
CHANGED
@@ -11,6 +11,12 @@ class ENVied
|
|
11
11
|
template("Envfile.tt")
|
12
12
|
end
|
13
13
|
|
14
|
+
desc "init:rails", "Generate all files needed for a Rails project"
|
15
|
+
define_method "init:rails" do
|
16
|
+
init
|
17
|
+
template("rails-initializer.tt", 'config/initializers/envied.rb')
|
18
|
+
end
|
19
|
+
|
14
20
|
desc "check", "Checks whether you environment contains the defined variables"
|
15
21
|
long_desc <<-LONG
|
16
22
|
Checks whether defined variables are present and valid in your shell.
|
data/lib/envied/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envied
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/envied/cli.rb
|
117
117
|
- lib/envied/templates/Envfile.tt
|
118
118
|
- lib/envied/templates/heroku-env-check.tt
|
119
|
+
- lib/envied/templates/rails-initializer.tt
|
119
120
|
- lib/envied/version.rb
|
120
121
|
- spec/envied_spec.rb
|
121
122
|
- spec/spec_helper.rb
|