early 0.2.0 → 0.3.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 +13 -0
- data/lib/early/travis.rb +31 -0
- data/lib/early.rb +9 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b2f1ac4df09e65aad485b8c4e18a14b5b6ba2f7ac5787ec0a3ffffa6478c4be
|
4
|
+
data.tar.gz: e4e97ba1090f82191a0c7da5a3e9ee006c7f7166d192d31762cac5eefc1c6bab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bf3bc17918d6049c450b4002c88378de6dd808ce0595d1efc8d9d55a02481ce93699db893576ddd71a6dd7dbc8acce783abc96f2f533734efe49d6820b00dae
|
7
|
+
data.tar.gz: c37a02534c10ef62c52875573bc0fc94219ca81fac68e66c986f6b6fe48b37fbb43079bdfc87e7161bfb1735e452296dbf8019bf2713f0e328e80c00c6be8094
|
data/README.md
CHANGED
@@ -60,6 +60,19 @@ require_relative 'early' # 👈
|
|
60
60
|
This will make sure, that the rules you wanted early to enforce have been
|
61
61
|
applied before any code in `config` has been run.
|
62
62
|
|
63
|
+
### Travis
|
64
|
+
|
65
|
+
If you are using Travis CI, you can auto-load the environment variables
|
66
|
+
specified in `.travis.yml` with:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
require 'early'
|
70
|
+
|
71
|
+
Early :development do
|
72
|
+
travis
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
63
76
|
## License
|
64
77
|
|
65
78
|
The gem is available as open source under the terms of the [MIT
|
data/lib/early/travis.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Early
|
5
|
+
class Travis
|
6
|
+
def self.from_config(path)
|
7
|
+
path = Pathname.new(path.to_s).expand_path
|
8
|
+
config = YAML.load_file(path)
|
9
|
+
|
10
|
+
envs = Array(config.dig('env', 'global')).map do |line|
|
11
|
+
line.split('=', 2)
|
12
|
+
end
|
13
|
+
|
14
|
+
new(envs)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(envs)
|
18
|
+
@envs = envs
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply(except: nil)
|
22
|
+
except = Array(except).map(&:to_s)
|
23
|
+
|
24
|
+
@envs.each do |name, value|
|
25
|
+
next if except.include?(name)
|
26
|
+
|
27
|
+
ENV[name] ||= value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
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.3.0'
|
11
11
|
|
12
12
|
class Configuration # :nodoc:
|
13
13
|
attr_reader :variables
|
@@ -29,6 +29,12 @@ module Early
|
|
29
29
|
def default(name, value)
|
30
30
|
@variables << DefaultVariable.new(name, value)
|
31
31
|
end
|
32
|
+
|
33
|
+
def travis(path = '.travis.yml', except: %w(DATABASE_URL))
|
34
|
+
Kernel.require "early/travis"
|
35
|
+
|
36
|
+
Travis.from_config(path).apply(except: except)
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
class DefaultVariable # :nodoc:
|
@@ -111,8 +117,8 @@ module Kernel
|
|
111
117
|
#
|
112
118
|
# A quick note about how <tt>ENV</tt> works in Ruby. It is a plain
|
113
119
|
# <tt>Object</tt> that is monkey patched to behave a bit like a hash. You can
|
114
|
-
# get
|
115
|
-
#
|
120
|
+
# get a variable with <tt>ENV['NAME']</tt> and you can set a variable with
|
121
|
+
# <tt>ENV['NAME'] = 'val'</tt>.
|
116
122
|
#
|
117
123
|
# Both of the operations explicitly require strings for the variable name and
|
118
124
|
# value. Passing a symbol to <tt>ENV[:NAME]</tt> will result in an error. The
|
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.3.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-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- early.gemspec
|
72
72
|
- lib/early.rb
|
73
|
+
- lib/early/travis.rb
|
73
74
|
homepage: https://github.com/gsamokovarov/early
|
74
75
|
licenses:
|
75
76
|
- MIT
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.7.
|
94
|
+
rubygems_version: 2.7.6
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: Checks for environment variables early in your program.
|