early 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/early.rb +16 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ca89071c14e1dc8c32c5493760ee17f2e5710fb743fb4ae289b7fa702662969
|
4
|
+
data.tar.gz: 88c1841a00119011ce55df8306c49748403a7b66506379e7224151d2690d13dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8918c2fe09c2521c81675d4ca6df4184df44e2ecdb0d8ea3d5fb26271ed28408d047d1b85c89e97f2d8765b4434fc4611e75da2a9980b19865472a262ab49c1f
|
7
|
+
data.tar.gz: b0148bb5b212c0152934c07b31addcc51584dcdbc390031decfddfdeefd1d9119cbdc4586074430e9a198eb0d999d69097d0467c86b65564d54d9d5462a30e3d
|
data/README.md
CHANGED
@@ -9,13 +9,15 @@ it early in your program to require or default a variable and then work with
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'early'
|
12
|
+
gem 'early', require: false
|
13
13
|
```
|
14
14
|
|
15
|
-
Afterwards make sure to call `Early` as early as possible in your application,
|
15
|
+
Afterwards, make sure to call `Early` as early as possible in your application,
|
16
16
|
to check the `ENV` variables, before you use them in your configuration layer:
|
17
17
|
|
18
18
|
```ruby
|
19
|
+
require 'early'
|
20
|
+
|
19
21
|
Early do
|
20
22
|
require :DATABASE_URL
|
21
23
|
require :REDIS_URL
|
@@ -35,6 +37,8 @@ If you want to use early with Rails, you can store the early configuration in
|
|
35
37
|
|
36
38
|
|
37
39
|
```ruby
|
40
|
+
require 'early'
|
41
|
+
|
38
42
|
Early do
|
39
43
|
require :ADMIN_NAME, :ADMIN_PASSWORD
|
40
44
|
require :MEETUP_API_KEY
|
@@ -60,3 +64,5 @@ applied before any code in `config` has been run.
|
|
60
64
|
|
61
65
|
The gem is available as open source under the terms of the [MIT
|
62
66
|
License](https://opensource.org/licenses/MIT).
|
67
|
+
|
68
|
+
[12f]: https://12factor.net
|
data/lib/early.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# piece of code is hit, which may happen late in the program runtime an be easy
|
8
8
|
# to miss.
|
9
9
|
module Early
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.2.0'
|
11
11
|
|
12
12
|
class Configuration # :nodoc:
|
13
13
|
attr_reader :variables
|
@@ -68,8 +68,8 @@ module Early
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Env returns the early environment. This is either the value of RAILS_ENV,
|
71
|
-
# RACK_ENV (in order) or the string <tt>'development'</tt> if neither of
|
72
|
-
# aforementioned environment variables are present.
|
71
|
+
# RACK_ENV (in that order) or the string <tt>'development'</tt> if neither of
|
72
|
+
# the aforementioned environment variables are present.
|
73
73
|
def self.env
|
74
74
|
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
75
75
|
end
|
@@ -79,22 +79,28 @@ module Early
|
|
79
79
|
def self.apply(config)
|
80
80
|
config.variables.each(&:apply)
|
81
81
|
end
|
82
|
+
|
83
|
+
# Accessing environment variables as constants. Raises Early::Error if
|
84
|
+
# missing.
|
85
|
+
def self.const_missing(name)
|
86
|
+
RequiredVariable.new(name).apply
|
87
|
+
end
|
82
88
|
end
|
83
89
|
|
84
90
|
module Kernel
|
91
|
+
module_function
|
92
|
+
|
85
93
|
# Early checks for environment variables availability. It provides a DSL that
|
86
94
|
# can require or set a default value for an environment variable. This will
|
87
95
|
# help you catch configuration errors earlier in your application runtime.
|
88
96
|
# Here is an example:
|
89
97
|
#
|
90
|
-
# Early do
|
91
|
-
# require :REDIS_URL
|
92
|
-
# default :PROVIDER, :generic
|
93
|
-
# end
|
98
|
+
# Early do require :REDIS_URL default :PROVIDER, :generic end
|
94
99
|
#
|
95
|
-
# Calling <tt>require :REDIS_URL</tt> will fail if <tt>ENV['REDIS_URL']</tt>
|
96
|
-
# <tt>nil</tt>, which means that it wasn't provided, before running the
|
97
|
-
# application. The error will give you information about the missing
|
100
|
+
# Calling <tt>require :REDIS_URL</tt> will fail if <tt>ENV['REDIS_URL']</tt>
|
101
|
+
# is <tt>nil</tt>, which means that it wasn't provided, before running the
|
102
|
+
# current application. The error will give you information about the missing
|
103
|
+
# variable:
|
98
104
|
#
|
99
105
|
# Early::Error (Variable ENV["REDIS_URL"] is missing)
|
100
106
|
#
|
@@ -116,7 +122,6 @@ module Kernel
|
|
116
122
|
# worry about it.
|
117
123
|
def Early(*envs, &block)
|
118
124
|
config = Early::Configuration.new(&block)
|
119
|
-
|
120
125
|
if envs.empty? || envs.find { |e| Early.env == e.to_s }
|
121
126
|
Early.apply(config)
|
122
127
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: early
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genadi Samokovarov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|