envied 0.5.0 → 0.6.0

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: 69f7fe8ec05529012ad80743d4f247714b22d369
4
- data.tar.gz: ffbe2982c00e40da4d468447305b6670721de047
3
+ metadata.gz: dea71b6724a7a89b51486ea15c3149ce380b171b
4
+ data.tar.gz: da45f75d1b3a18765f8bc05e43a321c1c140906f
5
5
  SHA512:
6
- metadata.gz: fa4e3adebfadefb43a023b953bfa0f92bb31b87199a8c6404ea0ffdcef542257b58d1981a36ed4105b9e3bb5a348f779a2b368f4c6425d9819b1106afc812b91
7
- data.tar.gz: 43666f2884ea8a9bc6ffb6d1b1e24f102330d94787e9f51b72a7a6815e91802d7fa516b6eb95b405fe4c4530acb9fb8a4abbd0b066a8a89d3d87b67eb0b3a971
6
+ metadata.gz: bb5e335de481a06773babe4c479df4b2c7ea7b19d427961a91fdb3187f4c14470628d3bcca27c652c5a01743682840b9e95722ef6eefd45e7b3602ea46a7988c
7
+ data.tar.gz: 82a4c9d0f3b30cc807d27038ef6f1b48ddc601d9d650e8457d6ff8b1bb25848e51ce8d6ffcab9fc5faea5eb168e55439be2187564459aa6972d05a0bef6880cd
@@ -1,4 +1,8 @@
1
- # 0.5.0 / unreleased
1
+ # 0.6.0 / 2014-08-13
2
+
3
+ * Configuration should now be put in `Envfile`
4
+
5
+ # 0.5.0 / 2014-07-02
2
6
 
3
7
  * add Array Hash types
4
8
 
data/README.md CHANGED
@@ -12,18 +12,18 @@ This gem will provide:
12
12
 
13
13
  ### 1) Configure
14
14
 
15
- Let's configure the ENV-variables we need:
15
+ After [successful installation](#installation), define some variables in `Envfile`:
16
16
 
17
17
  ```ruby
18
- ENVied.configure do
19
- variable :FORCE_SSL, :Boolean
20
- variable :PORT, :Integer
21
- end
18
+ # file: Envfile
19
+ variable :FORCE_SSL, :Boolean
20
+ variable :PORT, :Integer
22
21
  ```
23
22
 
24
23
  ### 2) Check for presence and coercibility
25
24
 
26
25
  ```ruby
26
+ # file: some file that'll be run on initialization (e.g. `config/application.rb`)
27
27
  ENVied.require
28
28
  ```
29
29
 
@@ -42,23 +42,37 @@ ENVied.FORCE_SSL # => false
42
42
 
43
43
  ## Configuration
44
44
 
45
+ ### Types
46
+
47
+ The following types are supported:
48
+
49
+ * `:String` (implied)
50
+ * `:Boolean` (e.g. '0'/'1', 'f'/'t', 'false'/'true', 'off'/'on', 'yes','no' for resp. true or false)
51
+ * `:Integer`
52
+ * `:Symbol`
53
+ * `:Date` (e.g. '2014-3-26')
54
+ * `:Time` (e.g. '14:00')
55
+ * `:Hash` (e.g. 'a=1&b=2' becomes `{'a' => '1', 'b' => '2'}`)
56
+ * `:Array` (e.g. 'tag1,tag2' becomes `['tag1', 'tag2']`)
57
+
45
58
  ### Groups
46
59
 
47
60
  Groups give you more flexibility to define when variables are needed.
48
61
  It's similar to groups in a Gemfile:
49
62
 
50
63
  ```ruby
51
- ENVied.configure do
52
- variable :FORCE_SSL, :Boolean
64
+ # file: Envfile
65
+ variable :FORCE_SSL, :Boolean
53
66
 
54
- group :production do
55
- variable :NEW_RELIC_LICENSE_KEY
56
- end
67
+ group :production do
68
+ variable :NEW_RELIC_LICENSE_KEY
57
69
  end
70
+ ```
58
71
 
72
+ ```ruby
59
73
  # For local development you would typically do:
60
74
  ENVied.require(:default) #=> Only ENV['FORCE_SSL'] is required
61
- # On the server:
75
+ # On the production server:
62
76
  ENVied.require(:default, :production) #=> ...also ENV['NEW_RELIC_LICENSE_KEY'] is required
63
77
 
64
78
  # BTW the following are equivalent:
@@ -68,19 +82,6 @@ ENVied.require('default')
68
82
  ENVied.require(nil)
69
83
  ```
70
84
 
71
- ### Types
72
-
73
- The following types are supported:
74
-
75
- * `:String` (implied)
76
- * `:Boolean` (e.g. '0'/'1', 'f'/'t', 'false'/'true', 'off'/'on', 'yes','no' for resp. true or false)
77
- * `:Integer`
78
- * `:Symbol`
79
- * `:Date` (e.g. '2014-3-26')
80
- * `:Time` (e.g. '14:00')
81
- * `:Hash` (e.g. 'a=1&b=2' becomes `{'a' => '1', 'b' => '2'}`)
82
- * `:Array` (e.g. 'tag1,tag2' becomes `['tag1', 'tag2']`)
83
-
84
85
  ### Defaults
85
86
 
86
87
  In order to let other developers easily bootstrap the application, you can assign defaults to variables.
@@ -89,13 +90,14 @@ Defaults can be a value or a `Proc` (see example below).
89
90
  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:
90
91
 
91
92
  ```ruby
92
- ENVied.configure(enable_defaults: ENV['RACK_ENV'] == 'development') do
93
- variable :FORCE_SSL, :Boolean, default: false
94
- variable :PORT, :Integer, default: proc {|envied| envied.FORCE_SSL ? 443 : 80 }
95
- end
93
+ # Envfile
94
+ enable_defaults! { ENV['RACK_ENV'] == 'development' }
95
+
96
+ variable :FORCE_SSL, :Boolean, default: false
97
+ variable :PORT, :Integer, default: proc {|envied| envied.FORCE_SSL ? 443 : 80 }
96
98
  ```
97
99
 
98
- Please remember that ENVied only **reads** from ENV; it doesn't set ENV-variables.
100
+ Please remember that ENVied only **reads** from ENV; it doesn't mutate ENV.
99
101
  Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set.
100
102
  As a rule of thumb you should only use defaults:
101
103
  * for local development
@@ -104,36 +106,37 @@ As a rule of thumb you should only use defaults:
104
106
  ### A more extensive example:
105
107
 
106
108
  ```ruby
109
+ # Envfile
107
110
  # We allow defaults for local development (and local tests), but want our CI
108
111
  # to mimic our production as much as possible.
109
112
  # New developers that don't have RACK_ENV set, will in this way not be presented with a huge
110
113
  # list of missing variables, as defaults are still enabled.
111
114
  not_production_nor_ci = ->{ !(ENV['RACK_ENV'] == 'production' || ENV['CI']) }
112
- ENVied.configure(enable_defaults: &not_production_nor_ci) do
113
- # Your code will likely not use ENVied.RACK_ENV (better use Rails.env),
114
- # we want it to be present though; heck, we're using it in this file!
115
- variable :RACK_ENV
116
-
117
- variable :FORCE_SSL, :Boolean, default: false
118
- variable :PORT, :Integer, default: 3000
119
- # generate the default value using the value of PORT:
120
- variable :PUBLIC_HOST_WITH_PORT, :String, default: proc {|envied| "localhost:#{envied.PORT}" }
121
-
122
- group :production do
123
- variable :MAIL_PAAS_USERNAME
124
- variable :DATABASE_URL
125
- end
126
-
127
- group :ci do
128
- # ci-only stuff
129
- end
130
-
131
- group :not_ci do
132
- # CI needs no puma-threads, and sidekiq-stuff etc.
133
- # Define that here:
134
- variable :MIN_THREADS, :Integer, default: 1
135
- # more...
136
- end
115
+ enable_defaults(&not_production_nor_ci)
116
+
117
+ # Your code will likely not use ENVied.RACK_ENV (better use Rails.env),
118
+ # we want it to be present though; heck, we're using it in this file!
119
+ variable :RACK_ENV
120
+
121
+ variable :FORCE_SSL, :Boolean, default: false
122
+ variable :PORT, :Integer, default: 3000
123
+ # generate the default value using the value of PORT:
124
+ variable :PUBLIC_HOST_WITH_PORT, :String, default: proc {|envied| "localhost:#{envied.PORT}" }
125
+
126
+ group :production do
127
+ variable :MAIL_PAAS_USERNAME
128
+ variable :DATABASE_URL
129
+ end
130
+
131
+ group :ci do
132
+ # ci-only stuff
133
+ end
134
+
135
+ group :not_ci do
136
+ # CI needs no puma-threads, and sidekiq-stuff etc.
137
+ # Define that here:
138
+ variable :MIN_THREADS, :Integer, default: 1
139
+ # more...
137
140
  end
138
141
 
139
142
  # Depending on our situation, we can now require the groups needed:
@@ -158,10 +161,14 @@ Add this line to your application's Gemfile:
158
161
 
159
162
  gem 'envied'
160
163
 
161
- And then execute:
164
+ Then bundle:
162
165
 
163
166
  $ bundle
164
167
 
168
+ And generate the `Envfile`:
169
+
170
+ $ bundle exec envied init
171
+
165
172
  ## Testing
166
173
 
167
174
  ```bash
@@ -18,9 +18,11 @@ 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.add_dependency "virtus", '~> 1.0.1'
22
- spec.add_dependency "rack"
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+ spec.add_dependency "virtus", '~> 1.0'
23
+ spec.add_dependency "rack", "~> 1.4"
24
+ spec.add_dependency "thor", "~> 0.15"
23
25
  spec.add_development_dependency "bundler", "~> 1.5"
24
26
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec", '~> 3.0.0'
27
+ spec.add_development_dependency "rspec", '~> 3.0'
26
28
  end
@@ -1,3 +1,5 @@
1
+ require 'envied/version'
2
+ require 'envied/cli'
1
3
  require 'virtus'
2
4
 
3
5
  class ENVied
@@ -36,9 +38,14 @@ class ENVied
36
38
  @enable_defaults
37
39
  end
38
40
 
41
+ def self.enable_defaults!(value = nil, &block)
42
+ value ||= block if block_given?
43
+ @enable_defaults = value
44
+ end
45
+
39
46
  class << self
40
- attr_writer :enable_defaults
41
47
  alias_method :defaults_enabled?, :enable_defaults
48
+ alias_method :enable_defaults=, :enable_defaults!
42
49
  attr_accessor :current_group
43
50
  end
44
51
 
@@ -56,8 +63,12 @@ class ENVied
56
63
  @configuration ||= build_configuration
57
64
  end
58
65
 
66
+ def self.configure(options = {}, &block)
67
+ deprecation_warning "ENVied.configure will be deprecated. Please generate an Envfile instead (see the envied command)."
68
+ configuration(options, &block)
69
+ end
70
+
59
71
  class << self
60
- alias_method :configure, :configuration
61
72
  attr_accessor :required_groups
62
73
  end
63
74
 
@@ -75,6 +86,7 @@ class ENVied
75
86
  else
76
87
  self.required_groups = [:default]
77
88
  end
89
+ ensure_configured!
78
90
  error_on_missing_variables!
79
91
  error_on_uncoercible_variables!
80
92
 
@@ -87,6 +99,23 @@ class ENVied
87
99
  @instance = group_configuration.new(env)
88
100
  end
89
101
 
102
+ def self.ensure_configured!
103
+ # Backward compat: load Envfile only when it's present
104
+ configure_via_envfile if envfile_exists?
105
+ end
106
+
107
+ def self.envfile
108
+ File.expand_path('Envfile')
109
+ end
110
+
111
+ def self.envfile_exists?
112
+ File.exists?(envfile)
113
+ end
114
+
115
+ def self.configure_via_envfile
116
+ configuration { eval(File.read(ENVied.envfile)) }
117
+ end
118
+
90
119
  def self.error_on_missing_variables!
91
120
  if missing_variable_names.any?
92
121
  raise "Please set the following ENV-variables: #{missing_variable_names.sort.join(',')}"
@@ -190,4 +219,8 @@ class ENVied
190
219
  def self.respond_to_missing?(method, include_private = false)
191
220
  @instance.respond_to?(method) || super
192
221
  end
222
+
223
+ def self.deprecation_warning(msg)
224
+ puts "DEPRECATION WARNING: #{msg}"
225
+ end
193
226
  end
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+
3
+ class ENVied
4
+ class Cli < Thor
5
+ include Thor::Actions
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ desc "init", "Generate a default Envfile in the current working directory."
9
+ def init
10
+ puts "Writing new Envfile to #{File.expand_path('Envfile')}"
11
+ template("Envfile.tt")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # A sample Envfile
2
+ # enable_defaults! { ENV['RACK_ENV'] != 'production' }
3
+
4
+ # variable :REDIS_URL, :String, default: 'redis://localhost:6379'
@@ -1,3 +1,3 @@
1
1
  class ENVied
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.1
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.1
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.15'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.15'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,18 +86,19 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 3.0.0
89
+ version: '3.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 3.0.0
96
+ version: '3.0'
83
97
  description: Ensure presence and type of your app's ENV-variables.
84
98
  email:
85
99
  - gert@thinkcreate.nl
86
- executables: []
100
+ executables:
101
+ - envied
87
102
  extensions: []
88
103
  extra_rdoc_files: []
89
104
  files:
@@ -94,12 +109,14 @@ files:
94
109
  - LICENSE.txt
95
110
  - README.md
96
111
  - Rakefile
112
+ - bin/envied
97
113
  - envied.gemspec
98
114
  - lib/envied.rb
115
+ - lib/envied/cli.rb
116
+ - lib/envied/templates/Envfile.tt
99
117
  - lib/envied/version.rb
100
118
  - spec/envied_spec.rb
101
119
  - spec/spec_helper.rb
102
- - underconstruction.gif
103
120
  homepage: https://github.com/eval/envied
104
121
  licenses:
105
122
  - MIT
@@ -112,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
129
  requirements:
113
130
  - - ">="
114
131
  - !ruby/object:Gem::Version
115
- version: '0'
132
+ version: 1.9.3
116
133
  required_rubygems_version: !ruby/object:Gem::Requirement
117
134
  requirements:
118
135
  - - ">="
@@ -120,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
137
  version: '0'
121
138
  requirements: []
122
139
  rubyforge_project:
123
- rubygems_version: 2.3.0
140
+ rubygems_version: 2.4.0
124
141
  signing_key:
125
142
  specification_version: 4
126
143
  summary: Ensure presence and type of ENV-variables
Binary file