envolve 1.0.1 → 1.1.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: bcf4d1b8c8e82829351a0c08bfd021da5f1bb0bd
4
- data.tar.gz: 2fcf17f17172ec0fe8ecae50aa3abfc32952e081
3
+ metadata.gz: 94e9f25547cce1d320142122f72d7d580f52bd1e
4
+ data.tar.gz: 3cc94c1b0a79e41cda8dd96d1713077ffcfb73d9
5
5
  SHA512:
6
- metadata.gz: 954bd0dc4b0d00bb6585d573f11048975219e27fc4828d50af831f10430b4801ba0788ecb69021aaba8ecd10d51139d44a99e163032d794bf11f2aeae168d868
7
- data.tar.gz: a7a4b3f7ba9f453e733cfd56997e48d4db87b41b1afc9de829db21b1e80ba49eed5ce5587cbd9bf05fc9cada002aaeaa68d4056ee391f015da836c9d7d74e0dc
6
+ metadata.gz: 30b91a69a0210626901e6a0aa6feb34948e5d97b0c6fa6e488dc7e2ab6f59351eaec3c74c2fb2e7f6008db9d3ebf8e9d391779b7dc11352ee1dd01f1f31717d0
7
+ data.tar.gz: 58e606ad44024f0752863505c9951ac27d8072973cdc55341288e11d52a4170193165e3ffbf0b1ff5b278bc1fda5c3eb3c2be7b2044dba0f52a4bd4499bf8c64
data/HISTORY.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Envolve Changelog
2
+ ## Version 1.1.0 - 2014-12-07
3
+
4
+ * Add the ability to have required properties
5
+
2
6
  ## Version 1.0.1
3
7
 
4
8
  * Fix bug where ENV is only retrieved 1 time ever [Issue #1](https://github.com/copiousfreetime/envolve/issues/1).
@@ -6,6 +6,7 @@ README.md
6
6
  Rakefile
7
7
  lib/envolve.rb
8
8
  lib/envolve/config.rb
9
+ lib/envolve/error.rb
9
10
  lib/envolve/version.rb
10
11
  tasks/default.rake
11
12
  tasks/this.rb
data/Rakefile CHANGED
@@ -7,9 +7,9 @@ This.email = "jeremy@copiousfreetime.org"
7
7
  This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
8
8
 
9
9
  This.ruby_gemspec do |spec|
10
- spec.add_development_dependency( 'rake' , '~> 10.3')
10
+ spec.add_development_dependency( 'rake' , '~> 10.4')
11
11
  spec.add_development_dependency( 'minitest' , '~> 5.4' )
12
- spec.add_development_dependency( 'rdoc' , '~> 4.1' )
12
+ spec.add_development_dependency( 'rdoc' , '~> 4.2' )
13
13
  spec.add_development_dependency( 'simplecov', '~> 0.9' )
14
14
  end
15
15
 
@@ -6,4 +6,5 @@ module Envolve
6
6
  end
7
7
  end
8
8
  require 'envolve/version'
9
+ require 'envolve/error'
9
10
  require 'envolve/config'
@@ -1,10 +1,11 @@
1
+ require 'envolve/error'
1
2
  module Envolve
2
3
  # Public: A Configuration class to hold your application configuration
3
4
  #
4
5
  # Feed it ENV or some other Hash-like object and it will allow you to access
5
6
  # the elements in that hash via methods.
6
7
  #
7
- # You can also tell it to only pull those items from the initial has that have
8
+ # You can also tell it to only pull those items from the initial hash that have
8
9
  # a particular prefix, and that prefix will be stripped off of the elements
9
10
  # for access.
10
11
  class Config
@@ -50,7 +51,7 @@ module Envolve
50
51
 
51
52
  # Public: Set a property, with possible transformations
52
53
  #
53
- # In the conversion of a the environment to the configuration properties
54
+ # In the conversion of the environment to the configuration properties
54
55
  # sometimes the keys and/or values need to be converted to a new name.
55
56
  #
56
57
  # All property transformations take place AFTER the initial keys have been downcased
@@ -59,13 +60,16 @@ module Envolve
59
60
  # property - the name of the property we want to appear in the configuration
60
61
  # key - the source key from the environment where this property comes from
61
62
  # value - the new value for this property
62
- # default - setting a default for this property should it not exist
63
+ # default - setting a default for this property should the environment not
64
+ # provide a value
65
+ # required - this property is required to be set via env. If it is not, an
66
+ # execption is raised when the environment is parsed
63
67
  #
64
68
  # value may also be a lambda, in which ase the lambda is given the original
65
69
  # value and the return value from the labmda is used for the new value.
66
70
  #
67
- def self.property( property, key: nil, value: nil, default: nil )
68
- properties[property] = { :key => key, :value => value, :default => default }
71
+ def self.property( property, key: nil, value: nil, default: nil, required: false )
72
+ properties[property] = { :key => key, :value => value, :default => default, :required => required }
69
73
  end
70
74
 
71
75
  # Internal: Return the hash holding the properties
@@ -75,7 +79,7 @@ module Envolve
75
79
  @_properties ||= Hash.new
76
80
  end
77
81
 
78
- # Internal: The internal hash holding all the keys and values
82
+ # Internal: The internal hash like item holding all the keys and values
79
83
  attr_reader :_env
80
84
 
81
85
  # Internal: The prefix to strip off all the keys
@@ -107,6 +111,7 @@ module Envolve
107
111
 
108
112
  # Internal: Transform the environment variables to propreties
109
113
  #
114
+ # Raises MissingPropertyError if the property is required
110
115
  # Returns the transformed hash
111
116
  def transform_properties( env, properties )
112
117
  transformed = env.to_h.dup
@@ -117,6 +122,7 @@ module Envolve
117
122
  if value = transformed.delete(src_key) then
118
123
  value = apply_transformation(value, trans[:value]) if trans[:value]
119
124
  elsif value.nil? then
125
+ ::Envolve::MissingPropertyError.raise(_prefix, src_key) if trans[:required]
120
126
  value = trans[:default] if trans[:default]
121
127
  end
122
128
  transformed[dest_key] = value
@@ -0,0 +1,8 @@
1
+ module Envolve
2
+ class Error < ::StandardError; end
3
+ class MissingPropertyError < Error
4
+ def self.raise(_prefix, env_var)
5
+ Kernel.raise(self, "Missing environment variable #{[ _prefix, env_var].compact.join('_').upcase}")
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Envolve
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start if ENV['COVERAGE']
3
3
 
4
- gem 'minitest'
5
4
  require 'minitest/autorun'
6
5
  require 'minitest/pride'
@@ -1,30 +1,38 @@
1
1
  require 'test_helper'
2
2
  require 'envolve/config'
3
3
 
4
- class PropertyConfig < ::Envolve::Config
5
- environment_source {
6
- {
7
- 'EV_TEST_1' => 'test-1',
8
- 'EV_TEST_2' => 'test-2',
9
- 'EV_FOO' => 'test-bar',
10
- 'EV_WIBBLE' => 'wobble',
4
+ class TestPropertyConfig < ::Minitest::Test
5
+ class PropertyConfig < ::Envolve::Config
6
+ environment_source {
7
+ {
8
+ 'EV_TEST_1' => 'test-1',
9
+ 'EV_TEST_2' => 'test-2',
10
+ 'EV_FOO' => 'test-bar',
11
+ 'EV_WIBBLE' => 'wobble',
12
+ }
11
13
  }
12
- }
13
14
 
14
- prefix 'ev'
15
+ prefix 'ev'
15
16
 
16
- property 'bar', :key => 'foo'
17
- property 'wibble', :value => lambda { |val| val.gsub('o', 'ee') }
18
- property 'ara', :default => 42, :value => lambda { |val| Integer(val) }
17
+ property 'bar', :key => 'foo'
18
+ property 'wibble', :value => lambda { |val| val.gsub('o', 'ee') }
19
+ property 'ara', :default => 42, :value => lambda { |val| Integer(val) }
19
20
 
20
- end
21
+ end
22
+
23
+ class PropertyMustConfig < ::Envolve::Config
24
+ property 'envolve_test_must', :required => true
25
+ end
26
+
27
+ class PrefixPropertyMustConfig < ::Envolve::Config
28
+ prefix 'envolve_test'
29
+ property 'required_property', :required => true
30
+ end
21
31
 
22
- class TestPropertyConfig < ::Minitest::Test
23
32
  def setup
24
33
  @config = PropertyConfig.new
25
34
  end
26
35
 
27
-
28
36
  def test_access_key_as_method
29
37
  assert_equal( 'test-1', @config.test_1 )
30
38
  end
@@ -50,4 +58,26 @@ class TestPropertyConfig < ::Minitest::Test
50
58
  assert_equal( 42, @config['ara'] )
51
59
  end
52
60
 
61
+
62
+ def test_required_property
63
+ assert_raises(::Envolve::MissingPropertyError) {
64
+ PropertyMustConfig.new
65
+ }
66
+ end
67
+
68
+ def test_required_property_error_message
69
+ begin
70
+ PropertyMustConfig.new
71
+ rescue ::Envolve::MissingPropertyError => e
72
+ assert_match( /\s+ENVOLVE_TEST_MUST\Z/, e.message )
73
+ end
74
+ end
75
+
76
+ def test_required_property_error_message_includes_prefix
77
+ begin
78
+ PrefixPropertyMustConfig.new
79
+ rescue ::Envolve::MissingPropertyError => e
80
+ assert_match( /\s+ENVOLVE_TEST_REQUIRED_PROPERTY\Z/, e.message )
81
+ end
82
+ end
53
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envolve
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.3'
19
+ version: '10.4'
20
20
  type: :development
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: '10.3'
26
+ version: '10.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4.1'
47
+ version: '4.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4.1'
54
+ version: '4.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,7 @@ files:
86
86
  - Rakefile
87
87
  - lib/envolve.rb
88
88
  - lib/envolve/config.rb
89
+ - lib/envolve/error.rb
89
90
  - lib/envolve/version.rb
90
91
  - tasks/default.rake
91
92
  - tasks/this.rb