envied 0.8.2 → 0.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d96082d1dc1fedf685dc01443f880342727f980
4
- data.tar.gz: 15edf9b6d7d41abd5f694a534ff092e422cffa4f
3
+ metadata.gz: 803c704396a34b45112c1e893d902f616146d826
4
+ data.tar.gz: 2886267c88374d9b75d02920f55ca0df9e025244
5
5
  SHA512:
6
- metadata.gz: 34036deeaaf2f1bb339b645ea3f6680aa72323a2e0f3c71d84da130ac8fe2d2b685cdc5f208d5c84bb7b6008d108cc121256a0c9e4806f24512cad2aa77a2e9b
7
- data.tar.gz: f6768c4c9a2deab86218b9579b41af302ecd18fdd0567a94041067b8d9c4bd4ef17337fa7b1738c78f1402b8ce67a3a4f2ca0cbc7ca8e361de4d3e276dfc4f5d
6
+ metadata.gz: 721fa2f72d8fbba07714eaf8efdaa93bd48b045defb67fdd4d2e0a56e7d78fe132e152a68762fe1586138b6624b6c2ea16a80ab9cd16f13b7bb22f8b26750c64
7
+ data.tar.gz: 44567081a050048fc3eec30c4c7746999aaf9d5a26cb6c6f80480d3b4464ae88caa3be21aa1247a96c6304c0050575759bb631bfefa118a0e6ee57b939efb140
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --warnings
2
- --format documentation
2
+ --format progress
3
3
  --color
@@ -6,8 +6,6 @@ before_install:
6
6
  - gem update bundler
7
7
 
8
8
  rvm:
9
- - 1.9.3
10
- - 2.0.0
11
9
  - 2.1.9
12
10
  - 2.2.6
13
11
  - 2.3.3
@@ -1,12 +1,19 @@
1
- ## unreleased
1
+ ## 0.9.0 / 2017-03-01
2
2
 
3
- ...
3
+ * Support multiple groups [#16](../../pull/16)
4
+ * Replaced rack dependency with stdlib solution using CGI for supporting hash type
5
+ * Now requiring Ruby 2.1.x and up
6
+ * Added float type which resolves [#30](../../pull/30)
7
+ * Added uri type [#22](../../pull/22)
8
+ * Updated extractor to find interpolated ENV vars which fixes [#21](../../pull/21)
9
+ * Various typo fixes [#24](../../pull/24) and [#28](../../pull/28)
10
+ * Resolved warnings when running tests
4
11
 
5
12
  ## 0.8.2 / 2017-02-21
6
13
 
7
14
  ### Added
8
15
 
9
- * Rails 5 support
16
+ * Rails 5 support [#25](../../pull/25)
10
17
 
11
18
  ### Fixed
12
19
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ENVied [![travis](https://secure.travis-ci.org/eval/envied.png?branch=master)](https://secure.travis-ci.org/#!/eval/envied)
1
+ # ENVied [![Build Status](https://travis-ci.org/eval/envied.svg?branch=master)](https://travis-ci.org/eval/envied)
2
2
 
3
3
  ### TL;DR ensure presence and type of your app's ENV-variables.
4
4
 
@@ -46,8 +46,8 @@ ENVied.require
46
46
  ```
47
47
 
48
48
  This will throw an error if:
49
- * not both `ENV['FORCE_SSL']` and `ENV['PORT']` are present.
50
- * the values can't be coerced to resp. Boolean and Integer.
49
+ * both `ENV['FORCE_SSL']` and `ENV['PORT']` are *not present*.
50
+ * the values *cannot* be coerced to a boolean and integer.
51
51
 
52
52
  ### 3) Use coerced variables
53
53
 
@@ -85,24 +85,30 @@ The following types are supported:
85
85
  * `:string` (implied)
86
86
  * `:boolean` (e.g. '0'/'1', 'f'/'t', 'false'/'true', 'off'/'on', 'no'/'yes' for resp. false and true)
87
87
  * `:integer`
88
+ * `:float`
88
89
  * `:symbol`
89
90
  * `:date` (e.g. '2014-3-26')
90
91
  * `:time` (e.g. '14:00')
91
92
  * `:hash` (e.g. 'a=1&b=2' becomes `{'a' => '1', 'b' => '2'}`)
92
93
  * `:array` (e.g. 'tag1,tag2' becomes `['tag1', 'tag2']`)
94
+ * `:uri` (e.g. 'http://www.google.com' becomes `URI.parse('http://www.google.com')`
93
95
 
94
96
  ### Groups
95
97
 
96
- Groups give you more flexibility to define when variables are needed.
98
+ Groups give you more flexibility to define when variables are needed.
97
99
  It's similar to groups in a Gemfile:
98
100
 
99
101
  ```ruby
100
102
  # file: Envfile
101
- variable :FORCE_SSL, :boolean
103
+ variable :FORCE_SSL, :boolean, default: 'false'
102
104
 
103
105
  group :production do
104
106
  variable :SECRET_KEY_BASE
105
107
  end
108
+
109
+ group :development, :staging do
110
+ variable :DEV_KEY
111
+ end
106
112
  ```
107
113
 
108
114
  ```ruby
@@ -131,7 +137,7 @@ ENVied.require(nil)
131
137
  In order to let other developers easily bootstrap the application, you can assign defaults to variables.
132
138
  Defaults can be a value or a `Proc` (see example below).
133
139
 
134
- Note that 'easily bootstrap' is quite the opposite of 'fail-fast when not all ENV-variables are present'. Therefor you should explicitly state whén defaults are allowed:
140
+ Note that 'easily bootstrap' is quite the opposite of 'fail-fast when not all ENV-variables are present'. Therefore you should explicitly state when defaults are allowed:
135
141
 
136
142
  ```ruby
137
143
  # Envfile
@@ -142,7 +148,7 @@ variable :PORT, :integer, default: proc {|envied| envied.FORCE_SSL ? 443 : 80 }
142
148
  ```
143
149
 
144
150
  Please remember that ENVied only **reads** from ENV; it doesn't mutate ENV.
145
- Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set.
151
+ Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set.
146
152
  As a rule of thumb you should only use defaults:
147
153
  * for local development
148
154
  * for ENV-variables that are solely used by your application (i.e. for `ENV['STAFF_EMAILS']`, not for `ENV['RAILS_ENV']`)
@@ -189,7 +195,7 @@ The easiest/quickest is to run:
189
195
  $ heroku config | bundle exec envied check:heroku
190
196
  ```
191
197
 
192
- This is equivalent to having the heroku config as your local environment and running `envied check --groups default production`.
198
+ This is equivalent to having the heroku config as your local environment and running `envied check:heroku --groups default production`.
193
199
 
194
200
  You want to run this right before a deploy to Heroku. This prevents that your app will crash during bootup because ENV-variables are missing from heroku config.
195
201
 
@@ -208,10 +214,7 @@ $ ./bin/heroku-env-check && git push live master
208
214
 
209
215
  ```bash
210
216
  bundle install
211
-
212
217
  bundle exec rspec
213
- # or
214
- bundle exec rake
215
218
  ```
216
219
 
217
220
  ## Developing
@@ -222,8 +225,8 @@ bundle exec pry --gem
222
225
 
223
226
  ## Contributing
224
227
 
225
- 1. Fork it ( http://github.com/eval/envied/fork )
226
- 2. Create your feature branch (`git checkout -b my-new-feature`)
227
- 3. Commit your changes (`git commit -am 'Add some feature'`)
228
- 4. Push to the branch (`git push origin my-new-feature`)
229
- 5. Create new Pull Request
228
+ 1. Fork it: http://github.com/eval/envied/fork
229
+ 2. Create your feature branch: `git checkout -b my-new-feature`
230
+ 3. Commit your changes: `git commit -am 'Add some feature'`
231
+ 4. Push to the branch: `git push origin my-new-feature`
232
+ 5. Create a new pull request for your feature branch
@@ -6,8 +6,8 @@ require "envied/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "envied"
8
8
  spec.version = ENVied::VERSION
9
- spec.authors = ["Gert Goet"]
10
- spec.email = ["gert@thinkcreate.nl"]
9
+ spec.authors = ["Gert Goet", "Javier Julio"]
10
+ spec.email = ["gert@thinkcreate.nl", "jjfutbol@gmail.com"]
11
11
  spec.summary = %q{Ensure presence and type of ENV-variables}
12
12
  spec.description = %q{Ensure presence and type of your app's ENV-variables.}
13
13
  spec.homepage = "https://github.com/eval/envied"
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = ">= 1.9.3"
21
+ spec.required_ruby_version = ">= 2.1.9"
22
22
  spec.add_dependency "coercible", "~> 1.0"
23
- spec.add_dependency "rack", ">= 1.4", (RUBY_VERSION < "2.2.2" ? "< 2" : "< 3")
24
23
  spec.add_dependency "thor", "~> 0.15"
25
24
  spec.add_development_dependency "bundler", "~> 1.5"
26
25
  spec.add_development_dependency "rake"
@@ -12,8 +12,26 @@ variable :RACK_ENV
12
12
 
13
13
  variable :FORCE_SSL, :boolean, default: 'false'
14
14
  variable :PORT, :integer, default: '3000'
15
+
16
+ variable :TAGS, :array, default: 'tag1,tag2'
17
+ # ENVied.TAGS
18
+ # => ['tag1', 'tag2']
19
+
15
20
  # generate the default value using the value of PORT:
16
- variable :PUBLIC_HOST_WITH_PORT, :string, default: proc {|envied| "localhost:#{envied.PORT}" }
21
+ variable :PUBLIC_HOST_WITH_PORT, :string, default: proc { |envied|
22
+ "localhost:#{envied.PORT}"
23
+ }
24
+
25
+ # Or better yet, use the URI type:
26
+ variable :SITE_URI, :uri, default: 'http://localhost:5000/'
27
+ # So with that you could now do:
28
+ # ```
29
+ # config.action_mailer.default_url_options = {
30
+ # protocol: ENVied.SITE_URI.scheme,
31
+ # host: ENVied.SITE_URI.host
32
+ # }
33
+ # config.action_mailer.asset_host = ENVied.SITE_URI.to_s
34
+ # ```
17
35
 
18
36
  group :production do
19
37
  variable :MAIL_PAAS_USERNAME
@@ -25,10 +25,10 @@ class ENVied
25
25
  def extract
26
26
  globs = options[:globs]
27
27
  globs << "{test,spec}/*" if options[:tests]
28
- var_occurences = ENVied::EnvVarExtractor.new(globs: globs).extract
28
+ var_occurrences = ENVied::EnvVarExtractor.new(globs: globs).extract
29
29
 
30
- puts "Found %d occurrences of %d variables:" % [var_occurences.values.flatten.size, var_occurences.size]
31
- var_occurences.sort.each do |var, occs|
30
+ puts "Found %d occurrences of %d variables:" % [var_occurrences.values.flatten.size, var_occurrences.size]
31
+ var_occurrences.sort.each do |var, occs|
32
32
  puts var
33
33
  occs.sort_by{|i| i[:path].size }.each do |occ|
34
34
  puts "* %s:%s" % occ.values_at(:path, :line)
@@ -8,8 +8,13 @@ class ENVied::Coercer
8
8
  end
9
9
 
10
10
  def to_hash(str)
11
- require 'rack/utils'
12
- ::Rack::Utils.parse_query(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)
13
18
  end
14
19
  end
15
20
  Coercible::Coercer::String.send(:include, CoercerExts)
@@ -38,7 +43,7 @@ class ENVied::Coercer
38
43
 
39
44
  def self.supported_types
40
45
  @supported_types ||= begin
41
- [:hash, :array, :time, :date, :symbol, :boolean, :integer, :string].sort
46
+ [:hash, :array, :time, :date, :symbol, :boolean, :integer, :string, :uri, :float].sort
42
47
  end
43
48
  end
44
49
 
@@ -45,9 +45,11 @@ class ENVied
45
45
  variables << ENVied::Variable.new(name, type, options)
46
46
  end
47
47
 
48
- def group(name, &block)
49
- @current_group = name.to_sym
50
- yield
48
+ def group(*names, &block)
49
+ names.each do |name|
50
+ @current_group = name.to_sym
51
+ yield
52
+ end
51
53
  ensure
52
54
  @current_group = nil
53
55
  end
@@ -24,7 +24,7 @@ class ENVied
24
24
  new(options.merge(globs: Array(globs))).extract
25
25
  end
26
26
 
27
- # Greps all ENV-variables from non-comment-parts of line.
27
+ # Greps all ENV-variables from a line of text.
28
28
  # Captures 'A' in lines like `ENV['A']`, but also `ENV.fetch('A')`.
29
29
  #
30
30
  # @param line [String] the line to grep
@@ -32,17 +32,14 @@ class ENVied
32
32
  # @example
33
33
  # extractor.new.capture_variables("config.force_ssl = ENV['FORCE_SSL']")
34
34
  # # => ["FORCE_SSL"]
35
- # extractor.new.capture_variables("# comment about ENV['FORCE_SSL']")
36
- # # => []
37
35
  #
38
36
  # @return [Array<String>] the names o
39
37
  def capture_variables(line)
40
- noncomment, _ = line.split("#", 2)
41
- noncomment.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten
38
+ line.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten
42
39
  end
43
40
 
44
41
  # Extract all keys recursively from files found via `globs`.
45
- # Any occurence of `ENV['A']` or `ENV.fetch('A')` in code (not in comments), will result
42
+ # Any occurrence of `ENV['A']` or `ENV.fetch('A')`, will result
46
43
  # in 'A' being extracted.
47
44
  #
48
45
  # @param globs [Array<String>] the collection of globs
@@ -1,3 +1,3 @@
1
1
  class ENVied
2
- VERSION = '0.8.2'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -28,6 +28,15 @@ describe ENVied::Coercer do
28
28
  end
29
29
  end
30
30
 
31
+ describe 'float coercion' do
32
+ let(:coerce){ coerce_to(:Float) }
33
+
34
+ it 'converts strings to floats' do
35
+ expect(coerce['1.05']).to eq 1.05
36
+ expect(coerce['-1.234']).to eq(-1.234)
37
+ end
38
+ end
39
+
31
40
  describe 'boolean coercion' do
32
41
  let(:coerce){ coerce_to(:Boolean) }
33
42
 
@@ -95,5 +104,13 @@ describe ENVied::Coercer do
95
104
  end
96
105
  end
97
106
  end
107
+
108
+ describe 'uri coercion' do
109
+ let(:coerce){ coerce_to(:Uri) }
110
+
111
+ it 'converts strings to uris' do
112
+ expect(coerce['http://www.google.com']).to be_a(URI)
113
+ end
114
+ end
98
115
  end
99
116
  end
@@ -10,9 +10,9 @@ describe ENVied::EnvVarExtractor do
10
10
  {
11
11
  %{self.a = ENV['A']} => %w(A),
12
12
  %{self.a = ENV["A"]} => %w(A),
13
+ %{self.a = ENV.fetch('A')]} => %w(A),
13
14
  %{self.a = ENV.fetch("A")]} => %w(A),
14
- %{self.a = ENV.fetch("A")]} => %w(A),
15
- %{# self.a = ENV["A"]} => %w(),
15
+ %{# self.a = ENV["A"]} => %w(A),
16
16
  %{self.a = ENV["A"] && self.b = ENV["B"]} => %w(A B),
17
17
  %{self.a = ENV["A3"]} => %w(A3)
18
18
  }.each do |line, expected|
@@ -96,7 +96,7 @@ describe ENVied do
96
96
  specify do
97
97
  expect {
98
98
  envied_require
99
- }.to raise_error(/The following environment variables should be set: a/)
99
+ }.to raise_error(RuntimeError, 'The following environment variables should be set: a.')
100
100
  end
101
101
  end
102
102
 
@@ -114,7 +114,7 @@ describe ENVied do
114
114
  it 'raises error when configuring variable of unknown type' do
115
115
  expect {
116
116
  configured_with(A: :Fixnum)
117
- }.to raise_error
117
+ }.to raise_error(ArgumentError, /Variable type \(of A\) should be one of \[/)
118
118
  end
119
119
  end
120
120
 
@@ -192,7 +192,7 @@ describe ENVied do
192
192
 
193
193
  expect {
194
194
  envied_require
195
- }.to raise_error
195
+ }.to raise_error(RuntimeError, 'The following environment variables should be set: A.')
196
196
  end
197
197
 
198
198
  it 'is ignored if ENV is provided' do
@@ -283,7 +283,7 @@ describe ENVied do
283
283
 
284
284
  expect {
285
285
  described_class.bar
286
- }.to raise_error
286
+ }.to raise_error(NoMethodError)
287
287
  end
288
288
 
289
289
  it 'requires variables without a group when requiring the default group' do
@@ -295,6 +295,28 @@ describe ENVied do
295
295
  end
296
296
  end
297
297
 
298
+ context 'a variable in multiple groups' do
299
+ before do
300
+ configure do
301
+ variable :moar
302
+
303
+ group :foo, :moo do
304
+ variable :bar
305
+ end
306
+ end.and_no_ENV
307
+ end
308
+
309
+ it 'is required when requiring any of the groups' do
310
+ expect {
311
+ envied_require(:foo)
312
+ }.to raise_error(/bar/)
313
+
314
+ expect {
315
+ envied_require(:moo)
316
+ }.to raise_error(/bar/)
317
+ end
318
+ end
319
+
298
320
  describe 'Hashable' do
299
321
  before do
300
322
  configure do
@@ -322,7 +344,7 @@ describe ENVied do
322
344
  it 'has no default by default' do
323
345
  # fixes a bug where variables of type :Hash had a default even
324
346
  # when none was configured.
325
- expect { envied_require }.to raise_error
347
+ expect { envied_require }.to raise_error(RuntimeError, 'The following environment variables should be set: baz.')
326
348
  end
327
349
  end
328
350
  end
@@ -339,6 +361,20 @@ describe ENVied do
339
361
  expect(ENVied.moar).to eq ['a',' b',' and, c']
340
362
  end
341
363
  end
364
+
365
+ describe 'URIable' do
366
+ before do
367
+ configure do
368
+ variable :site_url, :Uri
369
+ end.and_ENV('site_url' => 'https://www.google.com')
370
+ envied_require
371
+ end
372
+
373
+ it 'yields a URI from string' do
374
+ expect(ENVied.site_url).to be_a URI
375
+ expect(ENVied.site_url.host).to eq 'www.google.com'
376
+ end
377
+ end
342
378
  end
343
379
  end
344
380
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
8
+ - Javier Julio
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-02-21 00:00:00.000000000 Z
12
+ date: 2017-03-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: coercible
@@ -24,26 +25,6 @@ dependencies:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
27
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rack
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.4'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '3'
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '1.4'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '3'
47
28
  - !ruby/object:Gem::Dependency
48
29
  name: thor
49
30
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +84,7 @@ dependencies:
103
84
  description: Ensure presence and type of your app's ENV-variables.
104
85
  email:
105
86
  - gert@thinkcreate.nl
87
+ - jjfutbol@gmail.com
106
88
  executables:
107
89
  - envied
108
90
  extensions: []
@@ -147,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
129
  requirements:
148
130
  - - ">="
149
131
  - !ruby/object:Gem::Version
150
- version: 1.9.3
132
+ version: 2.1.9
151
133
  required_rubygems_version: !ruby/object:Gem::Requirement
152
134
  requirements:
153
135
  - - ">="