envied 0.0.2 → 0.0.3

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: e27f5b1d1bd52afb55a1bf4f4f7a106ad32d76da
4
- data.tar.gz: 055de0816f2bb6be30d74f8a20574aa627a51391
3
+ metadata.gz: 79a82b4ddfab5f725abe511edb302a7f82e74a31
4
+ data.tar.gz: b1627d78490f9ee58372b53c8699fecf572b36ef
5
5
  SHA512:
6
- metadata.gz: 9757b92de7e3dbe3d235032058898c8cae8a2a91e0086b55709545ea079a6c6074cb35d68d34076d892f356489e41ed63fd1924150b04de69650737e05818db1
7
- data.tar.gz: fb544d1f4fe81a2fcb9e3b345328cad98c1cd306c81c0af4bdac85bea64df2891994dd78f61c6a93e4179b3c291403efdb3d97b2206bdb19bf9beb27db76d2a2
6
+ metadata.gz: 9275f7c89ccd8159d921aae002558fa7eaedff0831944481c80a18d5c320cfc81fad2e7e049a81c78c349e463f8c5d19cf4143b4f1e98247a389ef3f694722b5
7
+ data.tar.gz: 0e98638933ffa8fdb57278ab0d6b1172ef62e6148eef582cf994727d70f62ab1faeedf931353a1bf38246cc85940979527bcdd79213b058297a9235f294cddc4
data/README.md CHANGED
@@ -1,48 +1,60 @@
1
- # ENVied or ENV on EPO
1
+ # ENVied
2
2
 
3
- ### TL;DR `ENVied` will improve your life drama-ti-cally.
3
+ ### TL;DR ensure presence and type of your app's ENV-variables.
4
4
 
5
- Say you're nicely configuring your app via ENV-variables, 'ey?
6
- Then maybe, just like me, you had the itch to check whether all variables your app needs, are present.
7
- Or you sometimes wish that ENV-variables should not only contain strings, but integers and booleans.
5
+ For applications that are configured via ENV-variables, this gem will provide:
8
6
 
9
- Wooha! You really should try `ENVied`.
7
+ * A fail-fast check for presence of required ENV-variables
8
+ * A fail-fast check for type of required ENV-variables
9
+ * Access to typed ENV-variables (instead of just strings)
10
10
 
11
- ![](underconstruction.gif)
12
-
13
- ## Installation
14
-
15
- Add this line to your application's Gemfile:
11
+ ### Current status
16
12
 
17
- gem 'envied'
13
+ ![](underconstruction.gif)
18
14
 
19
- And then execute:
15
+ ## Usage
20
16
 
21
- $ bundle
17
+ ### 1) Configure
22
18
 
23
- ## Usage
19
+ Let's configure the ENV-variables we need:
24
20
 
25
21
  ```ruby
26
- # in config/application.rb
27
- # somewhere after 'Bundler.require(*Rails.groups)':
22
+ # e.g. config/application.rb
28
23
  ENVied.configure do |env|
29
24
  env.variable :force_ssl, :Boolean
30
25
  env.variable :port, :Integer
31
26
  end
27
+ ```
32
28
 
33
- # require! will raise when ENV is *not* something like
34
- # {'FORCE_SSL' => 'true', 'PORT' => '3000'}
29
+ ### 2) Check for presence and type
30
+
31
+ ```ruby
35
32
  ENVied.require!
33
+ ```
34
+ Excecution will halt unless ENV is something like
35
+ `{'FORCE_SSL' => 'true', 'PORT' => '3000'}`.
36
36
 
37
- # existing app config starts here
38
- module Blog
39
- class Application < Rails::Application
40
- config.force_ssl = ENVied.force_ssl
41
- ...
42
- end
43
- end
37
+ A meaningful error will in this case explain what key and type is needed.
38
+
39
+ ### 3) Use typed variables
40
+
41
+ Variables accessed via ENVied have the configured type:
42
+
43
+ ```ruby
44
+ ENVied.port => 1
45
+ ENVied.force_ssl => false
44
46
  ```
45
47
 
48
+ ## Installation
49
+
50
+ Add this line to your application's Gemfile:
51
+
52
+ gem 'envied'
53
+
54
+ And then execute:
55
+
56
+ $ bundle
57
+
46
58
  ## Testing
47
59
 
48
60
  ```bash
@@ -62,7 +74,7 @@ bin/pry --gem
62
74
 
63
75
  ## Contributing
64
76
 
65
- 1. Fork it ( http://github.com/<my-github-username>/envied/fork )
77
+ 1. Fork it ( http://github.com/eval/envied/fork )
66
78
  2. Create your feature branch (`git checkout -b my-new-feature`)
67
79
  3. Commit your changes (`git commit -am 'Add some feature'`)
68
80
  4. Push to the branch (`git push origin my-new-feature`)
data/envied.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ENVied::VERSION
9
9
  spec.authors = ["Gert Goet"]
10
10
  spec.email = ["gert@thinkcreate.nl"]
11
- spec.summary = %q{ENV on epo}
12
- spec.description = %q{no, really}
11
+ spec.summary = %q{ENV on EPO}
12
+ spec.description = %q{ENV on EPO. Or: ensure presence and type of your app's ENV-variables.}
13
13
  spec.homepage = "https://github.com/eval/envied"
14
14
  spec.license = "MIT"
15
15
 
data/lib/envied.rb CHANGED
@@ -1,10 +1,30 @@
1
1
  class ENVied
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  module Configurable
4
4
  require 'virtus'
5
5
 
6
- class EnvMissing < StandardError;end
7
- class EnvWrongType < StandardError;end
6
+ class VariableError < StandardError
7
+ attr_reader :variable
8
+ def initialize(variable)
9
+ @variable = variable
10
+ end
11
+
12
+ def variable_type
13
+ variable.type.to_s.split("::").last
14
+ end
15
+ end
16
+
17
+ class VariableMissingError < VariableError
18
+ def message
19
+ "Please provide ENV['#{variable.name.to_s.upcase}'] of type #{variable_type}"
20
+ end
21
+ end
22
+
23
+ class VariableTypeError < VariableError
24
+ def message
25
+ "ENV['#{variable.name.to_s.upcase}'] should be of type #{variable_type}"
26
+ end
27
+ end
8
28
 
9
29
  def self.included(base)
10
30
  base.class_eval do
@@ -14,30 +34,27 @@ class ENVied
14
34
  end
15
35
 
16
36
  module ClassMethods
17
- # Creates an instance of Configuration.
37
+ # Creates a configuration instance from env.
18
38
  #
19
- # Will raise EnvMissing for variables Configuration defined
20
- # but are missing from env.
39
+ # Will raise VariableMissingError for variables not present in ENV.
21
40
  #
22
- # Will raise EnvWrongType for variables that can't be coerced to the
23
- # type defined in Configuration.
41
+ # Will raise VariableTypeError for variables whose ENV-value can't be coerced to the configured type.
24
42
  #
25
43
  # @param env [Hash] the env
26
44
  def parse_env(env)
27
45
  atts = attribute_set.map(&:name).each_with_object({}) do |name, result|
28
- @current_att = name
46
+ @variable = attribute_set[name]
29
47
  unless result[name] = env[name.to_s] || env[name.to_s.upcase]
30
- raise EnvMissing, "Please provide ENV['#{name.to_s.upcase}']"
48
+ raise VariableMissingError, @variable
31
49
  end
32
50
  end
51
+
33
52
  new(atts)
34
53
  rescue Virtus::CoercionError => e
35
- configured_type = attribute_set[@current_att].options[:primitive]
36
- raise EnvWrongType,
37
- "ENV['#{@current_att.to_s.upcase}'] should be of type %s" % configured_type
54
+ raise VariableTypeError, @variable
38
55
  end
39
56
 
40
- def variable(name, type = String, options = {})
57
+ def variable(name, type = :String, options = {})
41
58
  attribute name, type, { strict: true }.merge(options)
42
59
  end
43
60
  end
data/spec/envied_spec.rb CHANGED
@@ -47,13 +47,13 @@ describe ENVied do
47
47
  it 'raises EnvMissing on calling required!' do
48
48
  expect {
49
49
  ENVied.require!
50
- }.to raise_error(ENVied::Configurable::EnvMissing)
50
+ }.to raise_error(ENVied::Configurable::VariableMissingError)
51
51
  end
52
52
 
53
53
  it 'raises EnvMissing when interacted with and configured variable not present in ENV' do
54
54
  expect {
55
55
  ENVied.any_missing_method
56
- }.to raise_error(ENVied::Configurable::EnvMissing)
56
+ }.to raise_error(ENVied::Configurable::VariableMissingError)
57
57
  end
58
58
  end
59
59
 
@@ -63,7 +63,7 @@ describe ENVied do
63
63
  specify do
64
64
  expect {
65
65
  ENVied.a
66
- }.to raise_error(ENVied::Configurable::EnvWrongType)
66
+ }.to raise_error(ENVied::Configurable::VariableTypeError)
67
67
  end
68
68
  end
69
69
  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.0.2
4
+ version: 0.0.3
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-03-08 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0.beta2
69
- description: no, really
69
+ description: 'ENV on EPO. Or: ensure presence and type of your app''s ENV-variables.'
70
70
  email:
71
71
  - gert@thinkcreate.nl
72
72
  executables: []
@@ -106,7 +106,7 @@ rubyforge_project:
106
106
  rubygems_version: 2.2.0
107
107
  signing_key:
108
108
  specification_version: 4
109
- summary: ENV on epo
109
+ summary: ENV on EPO
110
110
  test_files:
111
111
  - spec/envied_spec.rb
112
112
  - spec/spec_helper.rb