early 0.2.0 → 0.3.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/lib/early/travis.rb +31 -0
  4. data/lib/early.rb +9 -3
  5. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ca89071c14e1dc8c32c5493760ee17f2e5710fb743fb4ae289b7fa702662969
4
- data.tar.gz: 88c1841a00119011ce55df8306c49748403a7b66506379e7224151d2690d13dc
3
+ metadata.gz: 0b2f1ac4df09e65aad485b8c4e18a14b5b6ba2f7ac5787ec0a3ffffa6478c4be
4
+ data.tar.gz: e4e97ba1090f82191a0c7da5a3e9ee006c7f7166d192d31762cac5eefc1c6bab
5
5
  SHA512:
6
- metadata.gz: 8918c2fe09c2521c81675d4ca6df4184df44e2ecdb0d8ea3d5fb26271ed28408d047d1b85c89e97f2d8765b4434fc4611e75da2a9980b19865472a262ab49c1f
7
- data.tar.gz: b0148bb5b212c0152934c07b31addcc51584dcdbc390031decfddfdeefd1d9119cbdc4586074430e9a198eb0d999d69097d0467c86b65564d54d9d5462a30e3d
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
@@ -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.2.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 an variable with <tt>ENV['NAME']</tt> and you can set an environment
115
- # variable with <tt>ENV['NAME'] = 'val'</tt>.
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.2.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-02-21 00:00:00.000000000 Z
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.3
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.