envied 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 803c704396a34b45112c1e893d902f616146d826
4
- data.tar.gz: 2886267c88374d9b75d02920f55ca0df9e025244
3
+ metadata.gz: 1eae6e996d1e0a70624b7c24167eccd631a5d9a0
4
+ data.tar.gz: d9df438b52137f7a22592b468a44895f7cd5a99d
5
5
  SHA512:
6
- metadata.gz: 721fa2f72d8fbba07714eaf8efdaa93bd48b045defb67fdd4d2e0a56e7d78fe132e152a68762fe1586138b6624b6c2ea16a80ab9cd16f13b7bb22f8b26750c64
7
- data.tar.gz: 44567081a050048fc3eec30c4c7746999aaf9d5a26cb6c6f80480d3b4464ae88caa3be21aa1247a96c6304c0050575759bb631bfefa118a0e6ee57b939efb140
6
+ metadata.gz: 6e770306eb9e9fb37130e5a3fb69be59d3c25443bbd1c36ab09303a9575ad884f0f4569755827f7e0f1362e05621d0c7ac6455d2eb438b620b2bd48e4f6ac3fb
7
+ data.tar.gz: 6a49f0e90abb416a73e3199961df26b4cdef5e83fa8c0b60e9053f46f4ed18cec7608faddb9b82fdaa726a9329922981135eb05c6a85043ae4052ca34ddff7bb
@@ -3,14 +3,13 @@ language: ruby
3
3
  before_install:
4
4
  - gem update --system
5
5
  - gem install bundler
6
- - gem update bundler
7
6
 
8
7
  rvm:
9
- - 2.1.9
10
- - 2.2.6
11
- - 2.3.3
12
- - 2.4.0
13
- - jruby-9.0.5.0
8
+ - 2.1.10
9
+ - 2.2.7
10
+ - 2.3.4
11
+ - 2.4.1
12
+ - jruby-9.1.12.0
14
13
  - jruby-head
15
14
 
16
15
  cache: bundler
@@ -1,3 +1,7 @@
1
+ ## 0.9.1 / 2017-07-06
2
+
3
+ * Updates `envied check:heroku` to support multiline ENV variables [#42](../../pull/42)
4
+
1
5
  ## 0.9.0 / 2017-03-01
2
6
 
3
7
  * Support multiple groups [#16](../../pull/16)
data/README.md CHANGED
@@ -95,7 +95,7 @@ The following types are supported:
95
95
 
96
96
  ### Groups
97
97
 
98
- Groups give you more flexibility to define when variables are needed.
98
+ Groups give you more flexibility to define when variables are needed.
99
99
  It's similar to groups in a Gemfile:
100
100
 
101
101
  ```ruby
@@ -147,7 +147,7 @@ variable :FORCE_SSL, :boolean, default: 'false'
147
147
  variable :PORT, :integer, default: proc {|envied| envied.FORCE_SSL ? 443 : 80 }
148
148
  ```
149
149
 
150
- Please remember that ENVied only **reads** from ENV; it doesn't mutate ENV.
150
+ Please remember that ENVied only **reads** from ENV; it doesn't mutate ENV.
151
151
  Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set.
152
152
  As a rule of thumb you should only use defaults:
153
153
  * for local development
@@ -192,7 +192,7 @@ It assumes a standard project layout (see the default value for the globs-option
192
192
  The easiest/quickest is to run:
193
193
 
194
194
  ```
195
- $ heroku config | bundle exec envied check:heroku
195
+ $ heroku config --json | bundle exec envied check:heroku
196
196
  ```
197
197
 
198
198
  This is equivalent to having the heroku config as your local environment and running `envied check:heroku --groups default production`.
@@ -2,6 +2,7 @@ require 'envied/version'
2
2
  require 'envied/cli'
3
3
  require 'envied/env_proxy'
4
4
  require 'envied/coercer'
5
+ require 'envied/coercer/envied_string'
5
6
  require 'envied/variable'
6
7
  require 'envied/configuration'
7
8
 
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'json'
2
3
  require 'envied/env_var_extractor'
3
4
 
4
5
  class ENVied
@@ -84,7 +85,7 @@ INIT
84
85
 
85
86
  The Heroku config should be piped to this task:
86
87
 
87
- heroku config | bundle exec envied check:heroku
88
+ heroku config --json | bundle exec envied check:heroku
88
89
 
89
90
  Use the check:heroku:binstub-task to turn this into a bash-script.
90
91
 
@@ -96,16 +97,12 @@ INIT
96
97
  define_method "check:heroku" do
97
98
  if STDIN.tty?
98
99
  error <<-ERR
99
- Please pipe the contents of `heroku config` to this task.
100
- I.e. `heroku config | bundle exec envied check:heroku`"
100
+ Please pipe the contents of `heroku config --json` to this task.
101
+ I.e. `heroku config --json | bundle exec envied check:heroku`"
101
102
  ERR
102
103
  exit 1
103
104
  end
104
- config = STDIN.read
105
- heroku_env = Hash[config.split("\n")[1..-1].each_with_object([]) do |i, res|
106
- res << i.split(":", 2).map(&:strip)
107
- end]
108
-
105
+ heroku_env = JSON.parse(STDIN.read)
109
106
  ENV.replace({}).update(heroku_env)
110
107
 
111
108
  requested_groups = ENV['ENVIED_GROUPS'] || options[:groups]
@@ -119,7 +116,7 @@ ERR
119
116
  long_desc <<-LONG
120
117
  Generates a shell script to check the Heroku config against the local Envfile.
121
118
 
122
- The same as the check:heroku-task, but all in one script (no need to pipe `heroku config` to it etc.).
119
+ The same as the check:heroku-task, but all in one script (no need to pipe `heroku config --json` to it etc.).
123
120
 
124
121
  LONG
125
122
  option :dest, banner: "where to put the script", desc: "Default: bin/<app>-env-check or bin/heroku-env-check"
@@ -2,23 +2,6 @@ require 'coercible'
2
2
 
3
3
  # Responsible for all string to type coercions.
4
4
  class ENVied::Coercer
5
- module CoercerExts
6
- def to_array(str)
7
- str.split(/(?<!\\),/).map{|i| i.gsub(/\\,/,',') }
8
- end
9
-
10
- def to_hash(str)
11
- require 'cgi'
12
- ::CGI.parse(str).map { |key, values| [key, values[0]] }.to_h
13
- end
14
-
15
- def to_uri(str)
16
- require 'uri'
17
- ::URI.parse(str)
18
- end
19
- end
20
- Coercible::Coercer::String.send(:include, CoercerExts)
21
-
22
5
  # Coerce strings to specific type.
23
6
  #
24
7
  # @param string [String] the string to be coerced
@@ -69,7 +52,7 @@ class ENVied::Coercer
69
52
  end
70
53
 
71
54
  def coercer
72
- @coercer ||= Coercible::Coercer.new[String]
55
+ @coercer ||= Coercible::Coercer.new[ENViedString]
73
56
  end
74
57
 
75
58
  def coerced?(value)
@@ -0,0 +1,23 @@
1
+ require 'coercible'
2
+
3
+ class ENVied::Coercer::ENViedString < Coercible::Coercer::String
4
+ def to_array(str)
5
+ str.split(/(?<!\\),/).map{|i| i.gsub(/\\,/,',') }
6
+ end
7
+
8
+ def to_hash(str)
9
+ require 'cgi'
10
+ ::CGI.parse(str).map { |key, values| [key, values[0]] }.to_h
11
+ end
12
+
13
+ def to_uri(str)
14
+ require 'uri'
15
+ ::URI.parse(str)
16
+ end
17
+
18
+ def to_integer(str)
19
+ Integer(str)
20
+ rescue ArgumentError
21
+ raise_unsupported_coercion(str, __method__)
22
+ end
23
+ end
@@ -3,7 +3,7 @@
3
3
  # Check the config of a Heroku app against the defined variables in `Envfile`
4
4
 
5
5
  <%- if @app %>
6
- HEROKU_APP=<%= @app %> exec heroku config | bundle exec envied check:heroku --groups <%= @groups.join(" ") %>
6
+ HEROKU_APP=<%= @app %> exec heroku config --json | bundle exec envied check:heroku --groups <%= @groups.join(" ") %>
7
7
  <%- else %>
8
- exec heroku config | bundle exec envied check:heroku --groups <%= @groups.join(" ") %>
8
+ exec heroku config --json | bundle exec envied check:heroku --groups <%= @groups.join(" ") %>
9
9
  <%- end %>
@@ -1,3 +1,3 @@
1
1
  class ENVied
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -10,8 +10,8 @@ describe ENVied::Coercer do
10
10
  ->(str){ coercer.coerce(str, type) }
11
11
  end
12
12
 
13
- describe 'string coercion' do
14
- let(:coerce){ coerce_to(:String) }
13
+ describe 'to string' do
14
+ let(:coerce){ coerce_to(:string) }
15
15
 
16
16
  it 'yields the input untouched' do
17
17
  expect(coerce['1']).to eq '1'
@@ -19,17 +19,23 @@ describe ENVied::Coercer do
19
19
  end
20
20
  end
21
21
 
22
- describe 'integer coercion' do
23
- let(:coerce){ coerce_to(:Integer) }
22
+ describe 'to integer' do
23
+ let(:coerce){ coerce_to(:integer) }
24
24
 
25
25
  it 'converts strings to integers' do
26
26
  expect(coerce['1']).to eq 1
27
27
  expect(coerce['-1']).to eq(-1)
28
28
  end
29
+
30
+ it 'fails for float' do
31
+ expect {
32
+ coerce['1.23']
33
+ }.to raise_error(Coercible::UnsupportedCoercion)
34
+ end
29
35
  end
30
36
 
31
- describe 'float coercion' do
32
- let(:coerce){ coerce_to(:Float) }
37
+ describe 'to float' do
38
+ let(:coerce){ coerce_to(:float) }
33
39
 
34
40
  it 'converts strings to floats' do
35
41
  expect(coerce['1.05']).to eq 1.05
@@ -37,8 +43,8 @@ describe ENVied::Coercer do
37
43
  end
38
44
  end
39
45
 
40
- describe 'boolean coercion' do
41
- let(:coerce){ coerce_to(:Boolean) }
46
+ describe 'to boolean' do
47
+ let(:coerce){ coerce_to(:boolean) }
42
48
 
43
49
  it "converts 'true' and 'false'" do
44
50
  expect(coerce['true']).to eq true
@@ -51,8 +57,8 @@ describe ENVied::Coercer do
51
57
  end
52
58
  end
53
59
 
54
- describe 'symbol coercion' do
55
- let(:coerce){ coerce_to(:Symbol) }
60
+ describe 'to symbol' do
61
+ let(:coerce){ coerce_to(:symbol) }
56
62
 
57
63
  it 'converts strings to symbols' do
58
64
  expect(coerce['a']).to eq :a
@@ -60,24 +66,24 @@ describe ENVied::Coercer do
60
66
  end
61
67
  end
62
68
 
63
- describe 'date coercion' do
64
- let(:coerce){ coerce_to(:Date) }
69
+ describe 'to date' do
70
+ let(:coerce){ coerce_to(:date) }
65
71
 
66
72
  it 'converts strings to date' do
67
73
  expect(coerce['2014-12-25']).to eq Date.parse('2014-12-25')
68
74
  end
69
75
  end
70
76
 
71
- describe 'time coercion' do
72
- let(:coerce){ coerce_to(:Time) }
77
+ describe 'to time' do
78
+ let(:coerce){ coerce_to(:time) }
73
79
 
74
80
  it 'converts strings to time' do
75
81
  expect(coerce['4:00']).to eq Time.parse('4:00')
76
82
  end
77
83
  end
78
84
 
79
- describe 'array coercion' do
80
- let(:coerce){ coerce_to(:Array) }
85
+ describe 'to array' do
86
+ let(:coerce){ coerce_to(:array) }
81
87
 
82
88
  it 'converts strings to array' do
83
89
  {
@@ -90,8 +96,8 @@ describe ENVied::Coercer do
90
96
  end
91
97
  end
92
98
 
93
- describe 'hash coercion' do
94
- let(:coerce){ coerce_to(:Hash) }
99
+ describe 'to hash' do
100
+ let(:coerce){ coerce_to(:hash) }
95
101
 
96
102
  it 'converts strings to hashes' do
97
103
  {
@@ -105,8 +111,8 @@ describe ENVied::Coercer do
105
111
  end
106
112
  end
107
113
 
108
- describe 'uri coercion' do
109
- let(:coerce){ coerce_to(:Uri) }
114
+ describe 'to uri' do
115
+ let(:coerce){ coerce_to(:uri) }
110
116
 
111
117
  it 'converts strings to uris' do
112
118
  expect(coerce['http://www.google.com']).to be_a(URI)
@@ -70,7 +70,7 @@ describe ENVied do
70
70
  end
71
71
 
72
72
  it 'responds to configured variables' do
73
- configured_with(a: :Integer).and_ENV({'a' => '1'})
73
+ configured_with(a: :integer).and_ENV({'a' => '1'})
74
74
  envied_require
75
75
 
76
76
  expect(described_class).to respond_to :a
@@ -84,14 +84,14 @@ describe ENVied do
84
84
  end
85
85
 
86
86
  it 'sets ENVied.config' do
87
- configured_with(a: :Integer).and_ENV({'a' => '1'})
87
+ configured_with(a: :integer).and_ENV({'a' => '1'})
88
88
  envied_require
89
89
 
90
90
  expect(ENVied.config).to_not be(nil)
91
91
  end
92
92
 
93
93
  context 'ENV contains not all configured variables' do
94
- before { configured_with(a: :Integer).and_no_ENV }
94
+ before { configured_with(a: :integer).and_no_ENV }
95
95
 
96
96
  specify do
97
97
  expect {
@@ -101,19 +101,19 @@ describe ENVied do
101
101
  end
102
102
 
103
103
  context 'ENV variables are not coercible' do
104
- before { configured_with(A: :Integer).and_ENV('A' => 'NaN') }
104
+ before { configured_with(A: :integer).and_ENV('A' => 'NaN') }
105
105
 
106
106
  specify do
107
107
  expect {
108
108
  envied_require
109
- }.to raise_error(/A \('NaN' can't be coerced to Integer/)
109
+ }.to raise_error(/A \('NaN' can't be coerced to integer/)
110
110
  end
111
111
  end
112
112
 
113
113
  context 'configuring' do
114
114
  it 'raises error when configuring variable of unknown type' do
115
115
  expect {
116
- configured_with(A: :Fixnum)
116
+ configured_with(A: :fixnum)
117
117
  }.to raise_error(ArgumentError, /Variable type \(of A\) should be one of \[/)
118
118
  end
119
119
  end
@@ -121,7 +121,7 @@ describe ENVied do
121
121
  context 'bug: default value "false" is not coercible' do
122
122
  before {
123
123
  configure(enable_defaults: true) do
124
- variable :FORCE_SSL, :Boolean, default: true
124
+ variable :FORCE_SSL, :boolean, default: true
125
125
  end
126
126
  }
127
127
 
@@ -169,7 +169,7 @@ describe ENVied do
169
169
  describe 'assigning' do
170
170
  it 'can be a value' do
171
171
  configure(enable_defaults: true) do
172
- variable :A, :Integer, default: '1'
172
+ variable :A, :integer, default: '1'
173
173
  end
174
174
  envied_require
175
175
 
@@ -178,7 +178,7 @@ describe ENVied do
178
178
 
179
179
  it 'can be a Proc' do
180
180
  configure(enable_defaults: true) do
181
- variable :A, :Integer, default: proc { "1" }
181
+ variable :A, :integer, default: proc { "1" }
182
182
  end
183
183
  envied_require
184
184
 
@@ -187,7 +187,7 @@ describe ENVied do
187
187
 
188
188
  it 'is ignored if defaults are disabled' do
189
189
  configure(enable_defaults: false) do
190
- variable :A, :Integer, default: "1"
190
+ variable :A, :integer, default: "1"
191
191
  end.and_no_ENV
192
192
 
193
193
  expect {
@@ -197,7 +197,7 @@ describe ENVied do
197
197
 
198
198
  it 'is ignored if ENV is provided' do
199
199
  configure(enable_defaults: true) do
200
- variable :A, :Integer, default: "1"
200
+ variable :A, :integer, default: "1"
201
201
  end.and_ENV('A' => '2')
202
202
  envied_require
203
203
 
@@ -206,8 +206,8 @@ describe ENVied do
206
206
 
207
207
  it 'can be defined in terms of other variables' do
208
208
  configure(enable_defaults: true) do
209
- variable :A, :Integer
210
- variable :B, :Integer, default: proc {|env| env.A * 2 }
209
+ variable :A, :integer
210
+ variable :B, :integer, default: proc {|env| env.A * 2 }
211
211
  end.and_ENV('A' => '1')
212
212
  envied_require
213
213
 
@@ -320,8 +320,8 @@ describe ENVied do
320
320
  describe 'Hashable' do
321
321
  before do
322
322
  configure do
323
- variable :foo, :Hash
324
- variable :bar, :Hash
323
+ variable :foo, :hash
324
+ variable :bar, :hash
325
325
  end.and_ENV('foo' => 'a=1&b=&c', 'bar' => '')
326
326
  envied_require
327
327
  end
@@ -337,7 +337,7 @@ describe ENVied do
337
337
  context 'with defaults enabled' do
338
338
  before do
339
339
  configure(enable_defaults: true) do
340
- variable :baz, :Hash
340
+ variable :baz, :hash
341
341
  end.and_no_ENV
342
342
  end
343
343
 
@@ -352,7 +352,7 @@ describe ENVied do
352
352
  describe 'Arrayable' do
353
353
  before do
354
354
  configure do
355
- variable :moar, :Array
355
+ variable :moar, :array
356
356
  end.and_ENV('moar' => 'a, b, and\, c')
357
357
  envied_require
358
358
  end
@@ -365,7 +365,7 @@ describe ENVied do
365
365
  describe 'URIable' do
366
366
  before do
367
367
  configure do
368
- variable :site_url, :Uri
368
+ variable :site_url, :uri
369
369
  end.and_ENV('site_url' => 'https://www.google.com')
370
370
  envied_require
371
371
  end
@@ -10,6 +10,6 @@ describe ENVied::Variable do
10
10
  end
11
11
 
12
12
  describe 'an instance' do
13
- subject { variable(:A, :String) }
13
+ subject { variable(:A, :string) }
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-01 00:00:00.000000000 Z
12
+ date: 2017-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coercible
@@ -104,6 +104,7 @@ files:
104
104
  - lib/envied.rb
105
105
  - lib/envied/cli.rb
106
106
  - lib/envied/coercer.rb
107
+ - lib/envied/coercer/envied_string.rb
107
108
  - lib/envied/configuration.rb
108
109
  - lib/envied/env_proxy.rb
109
110
  - lib/envied/env_var_extractor.rb
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
138
  version: '0'
138
139
  requirements: []
139
140
  rubyforge_project:
140
- rubygems_version: 2.6.8
141
+ rubygems_version: 2.6.12
141
142
  signing_key:
142
143
  specification_version: 4
143
144
  summary: Ensure presence and type of ENV-variables